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;
}
}
}

It seems to me after reading your code that you have a java.lang.NullPointerException problem.
If you fix the code on line 35, that may work.
Sorry for the late post,
Glad I could help.

-Sorry I forgot my password
commented: Spam +0
commented: nonsense -3

hmm looks like you havent initialized your 2D classList array:

classList = new String[100][100];

java.initialize.classlist;
should help
or
sys.out.initializationofclasslist.jpg

Sorry for the late post,
Glad I could help.

`-Sorry I forgot my passwor.d`
commented: Gibberish +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.