So I wrote this code to read a file containing numbers, however I get a NullPointerException error, when I try to assign value to the array.
Here is my code:
private static int []a;
public static int i = 0;
public static void main(String[] args) {
// Get a random generated array
// I'll read from file, which contains generated list of numbers.
BufferedReader reader = null;
try {
File file = new File("numbers.txt");
reader = new BufferedReader(new FileReader(file));
for(String line = reader.readLine(); line!= null; line = reader.readLine()){
//I get error here
a[i] = Integer.parseInt(line);
i++;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
C++in this question? This looks like Java.