My application is intended to read an existing text file, line for line, of exactly 1500 items into an array of item class objects. The goal is to get the data into the array so I can use this application as a starting point for converting the archive for a new program I am writing.
package sandboxPackage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class mainClass {
public static void main(String[]args) throws FileNotFoundException, IOException {
InputStream in = new FileInputStream(new File("C:\\Documents and Settings\\Adam\\Desktop\\Cloud Project\\MasterIndex.library"));
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder out = new StringBuilder();
String line;
itemClass[] m = new itemClass[1500];
int i = 0;
while ((line = reader.readLine()) != null) {
m[i].index = line; // crash is here
m[i].location = reader.readLine();
m[i].item = reader.readLine();
m[i].description = reader.readLine();
i++;
}
//Print the entire list
for (i = 0; i == 1499; i++) {
System.out.println(m[i].index);
System.out.println(m[i].location);
System.out.println(m[i].item);
System.out.println(m[i].description);
//System.out.println("This is item #" + i + 1);
}
}
}
And here is the itemClass:
package sandboxPackage;
public class itemClass{
String index;
String item;
String description;
String location;
}
The text file looks like this: Index Location Item Description Index Location Item Description Index ..
The compiler claims the NullPointerException is on line 20, which is the first line of the while loop, but I just don't see it. I have looked at about a thousand other examples of this same error but it still does not compute for me.