I am getting a null pointer exception on line 36 of this code, I do not understand how any of my values are null because they should all be filled with data from the text document. What am I doing wrong?
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class FileHandling {
static String[] className;
static String[][] classList;
static int counter = 0;
public static void main(String args[]){
className = new String[100];
try{
FileInputStream fstream = new FileInputStream("classNames.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
className[counter]=strLine;
counter+=1;
}
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}//end try/catch
String output = "";
int i=0;
int num=0;
while (num<counter){
String[] classmate = className[num].split( ",\\s*" );
for ( String string : classmate ){
i+=1;
output += "\"" + string + "\", ";
classList[num][i]=string;
}
i=0;
num+=1;
}//end while
//while (true){
//menu
//}
}//end method
public void showClass(){
int i=0;
int num=0;
while (num<counter){
while (i<3){
System.out.println(classList[num][i]);
i+=1;
}
num+=1;
i=0;
}
}
}