r/javahelp • • Sep 23 '19

Solved Java compiler keeps telling me that my public class name needs to match my file name, BUT IT DOES. Why is it doing this?

RunsPrinter.java

public class RunsPrinter {

FUCKIN ERROR

0 Upvotes

7 comments sorted by

4

u/Lvl20Rogue Sep 23 '19

Is that the whole file?

2

u/casual_microwave Sep 23 '19

Lol no. I wrote out a bunch of code, tried to compile, and it’s 1 complaint is that my class name needs to match the name of the file, but it does. And I don’t get it. This thing is due in 45 minutes and it keeps doing this

3

u/Lvl20Rogue Sep 23 '19

Sometimes The error message can be a bit cryptical or even incorrect. So on the off chance that it's something else you should probably post the whole file

2

u/casual_microwave Sep 23 '19

Idk what happened but it just stopped making that error when I wrote more code

2

u/bobphorous Sep 23 '19

Because there is an error somewhere. The compiler just gives you what it sees. Even though it seems like it sometimes, the compiler is not there to frustrate you.

Screenshot the filename, the classname and the error. The program may be having an error that is causing this error. One thing you can try is to create a new file and copy the classname to the filename and copy paste the contents into the file and replace the one giving the error. If that doesn't fix the problem, you could try using an IDE like intellij. They tend to be fairly helpful with identifying errors and autocomplete.

0

u/casual_microwave Sep 23 '19

Yeah idk why but I wrote more code and the error went away.

2

u/wildjokers Sep 23 '19

You had a syntax error that was causing the compiler to see other characters as part of your class name. It is very important to post the whole file when something like that happens. The compiler won't lie to you.