I am getting the following exception
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Java.CompileFile.doCompilation(CompileFile.java:48)
at GUI.CompilerForm.compileBtnActionPerformed(CompilerForm.java:225)
at GUI.CompilerForm.access$400(CompilerForm.java:23)
............
I no the error is at line 48 in CompileFile.java, it is saying that the array in NULL and i dont know why because that is where i am adding strings to it!
String[] compile;
int numberOfErrors = 0;
.
.
.
for (Diagnostic diagnostic : diagnostics.getDiagnostics()) {
String errors = diagnostic.getKind().toString()+" on line "+ diagnostic.getLineNumber() +"\nIn file: \n"+ diagnostic.toString();
compile[numberOfErrors] = errors;
numberOfErrors++;
}
I have tried System.out.println(errors); straight after i set it and it is working fine so i really dont know what is going on!
Any suggestions?
You’ve declared a variable called
compile, but you haven’t shown anywhere that it’s given a value. Assuming it’s an instance variable, its value will default tonull. You need to initialize it with:where
someSizeis “big enough”.Alternatively, and preferrably, you could use a list:
then…
Then you can probably get rid of
numberOfErrorstoo, as that would just becompile.size()presumably.