Why does Java throw NullPointerException here?

后端 未结 5 2011
半阙折子戏
半阙折子戏 2020-11-30 15:09
public class Test {

    public int [] x;

    public Test(int N)
    {
       int[] x = new int [N];
       for (int i=0;i

        
5条回答
  •  时光说笑
    2020-11-30 15:27

     int size=reader.readInt();  // size < 3
     StdOut.println(N.x[3]); // length of x[] less than 3, so x[3] case NullPointException
    

提交回复
热议问题