Java Array数组错误 Exception in thread "main" java.lang.NullPointerException

Array数组必须指定length

比如,

public class test{
   private String name;
   private String pwd;
   private String[] account=new String[3];
   public test(String a, String b,String c,String d,String f){
       name=a;
       pwd=b;
       account[0]=c;
       account[1]=d;
       account[2]=f;

       //这地方不报空指针才怪
       account[3]=f;
   }
   public static void main(String[] args){
       test newTest = new test("1","2","2","2","2"); 
       System.out.print(newTest.account[0]);
   }

}

 

posted @ 2019-02-22 16:27  JokerJason  阅读(915)  评论(0编辑  收藏  举报

It's not who you are underneath, it's what you do that defines you

Brick walls are there for a reason :they let us prove how badly we want things