I currently have a class Printer
which is accessed statically, but when I try to compile the project after adding a function to the class I get error: cannot find symbol
.
I know this is generally caused by typos, out-of-scope references and bad declarations, but the odd thing here is that the old methods work just fine.
This code has exactly the same structure as my own code, and it works:
import java.util.*;
import java.lang.*;
import java.io.*;
class Printer {
private static String errorTitle;
private static String regularTitle;
Printer(String regularTitle_) {
errorTitle = "Some error: ";
regularTitle = regularTitle_;
}
public static void printError(Exception e) {
System.out.println(errorTitle + e.getMessage());
}
public static void print(String message) {
System.out.println(regularTitle + message);
}
}
class Main {
public static void main(String[] args) {
new Printer("Message: ");
try {
throw new Exception();
}
catch(Exception e) {
//This works
Printer.print(e.toString());
//This generates a cannot find symbol error when compiling
Printer.printError(e);
// ^ here
}
}
}
The complete error message is:
[javac] Compiling 1 source file to C:\Javaprojects\MyProject\alpha\build
[javac] C:\Javaprojects\MyProject\alpha\src\Main.java:35 error: cannot find symbol
[javac] Printer.printError(e);
[javac] ^
[javac] symbol: method printError(Exception)
[javac] location: class Printer
[javac] 1 error
This works fine if I change Printer.printError(e)
to Printer.print(e.toString())
.
What can possibly be the cause of this? Could it be that I am referring to some sort of cached version of the compiled class?