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

Edited 4 Years Ago by jarograv

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
Comments
nonsense
Spam

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

classList = new String[100][100];

Edited 4 Years Ago by DavidKroukamp

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`

Edited 4 Years Ago by diafol: You are posting gibberish. Please keep it organised

Comments
Gibberish
This article has been dead for over six months. Start a new discussion instead.