nullpointerexception for array of objects -


i have following test class

public class driver {     public static void main(string [] args)         {              bankaccount[] b1 = {new bankaccount(200), new bankaccount(300), new bankaccount(250), new bankaccount(300), new bankaccount(200)};               bankaccountgroup bag = new bankaccountgroup(b1);                                } 

and bankaccountgroup:

public class bankaccountgroup  {  private bankaccount bank[]; public bankaccountgroup(bankaccount[]b) { for(int =0; i<5;i++) { bank[i] = b[i]; } } 

these snippets of whole code. im getting nullpointerexception these 2 lines: - bank[i] = b[i]; - bankaccountgroup bag = new bankaccountgroup(b1); please help

when declare bank[] in bankaccountgroup class looks forgot give length. because of this, when call bank[i] in loop, after i=0 going give error.

something like

private bankaccount[] bank = new bankaccount[5]; 

Comments