My code compiles, but I get this error at runtime:
Exception in thread "main" java.lang.ExceptionInInitializerError
at GUI.<init>(GUI.java:46)
at GUI.main(GUI.java:252)
Caused by: java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at java.util.Arrays$ArrayList.<init>(Arrays.java:3813)
at java.util.Arrays.asList(Arrays.java:3800)
at db.<clinit>(db.java:23)
... 2 more
This is the code causing the error:
public static String strLine;
public static String[] filearray;
public static List<String> list = Arrays.asList(filearray);
public static void load() throws IOException{
FileInputStream in = new FileInputStream("slist.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
filearray = new String[4];
while ((strLine = br.readLine()) != null) {
for (int j = 0; j < filearray.length; j++){
filearray[j] = br.readLine();
}
}
in.close();
Line 46 referenced in the error:
JList stafflist = new JList(db.list.toArray());
I am trying to load a text file as an Array and add it to the JList stafflist, but I get a runtime error.