The following code shows the following error:
Exception in thread "main" java.lang.NullPointerException at cdtWorkspace.swap.main(swap.java:25)
PS: I have initialized a scanner object globally as static
.
15 public static void main(String args[] ) throws Exception {
16
17 int n=scn.nextInt();
18 int[][] param=new int[n][2];
19 int[][] arr=new int[n][];
20 for(int i=0; i<n;i++){
21 param[i][0]=scn.nextInt();
22 param[i][1]=scn.nextInt();
23 int j=0;
24 while (j<param[i][0]){
25 arr[i][j]=scn.nextInt();
26 j++;
27 }
28 }
29 }
I am getting the same error each time i try to fill in an array using a for loop! Any suggestions?