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]);
   }

}

 

    原文作者:JokerJason
    原文地址: https://www.cnblogs.com/jokerjason/p/10419147.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞