Null pointer access: The variable number can only be null at this location。 错误解决

public class FeiBoNa {
 public static void main(String[] args) {
  int[] number = null;
  number[0] = 0;
  number[1] = 1;
  number[2] = 1;
  int m;
  for(m=3;m<30001;m++){
   number[m] = number[m-1]+number[m-2];
  }
  System.out.print(number[m]);
 }
}


错误:Exception in thread "main" java.lang.NullPointerException
 at FeiBoNa.main(FeiBoNa.java:6)
两个空格没有粘贴,就以上代码而言,错误为:at FeiBoNa.main(FeiBoNa.java:4)。number[0] = 0 当中,"number"带有黄色下划线警告,警告内容为:Null pointer access: The variable number can only be null at this location。
 
 
int[] number = null;
这句不对,数组必须初始化才行,比如 int[] number = new int[3];

你可能感兴趣的:(Null pointer access: The variable number can only be null at this location。 错误解决)