In the following program, I am trying to get values in an array from user. However, I am getting NullPointerException after entering only two values. Can someone explain why I am getting this exception?
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class MemoriseMe{
static int arr1[],count;
public static void main(String[] args) throws IOException
{
BufferedReader brObj = new BufferedReader(new InputStreamReader(System.in));
int firstQuery =Integer.parseInt(brObj.readLine());
System.out.println("Enter the elements : ");
String line = brObj.readLine(); // to read multiple integers line
String[] strs = line.trim().split("\\s+");
for(int i =0;i<firstQuery;i++)
{
arr1[i]=Integer.parseInt(brObj.readLine());
}
}
}