loading...

re: Why does this Java code keep throwing Exception in thread "main" at line 8 when line 8 is the declaration for the main method? VIEW POST

FULL DISCUSSION
 

What it might be is that your class is not declared public but your main method is. You cannot have a larger scope for an enclosed method than the scope of the class itself, and classes are -- by default -- package-private. Try adding public before class and see if that helps.

In Java, each *.java file should contain a single class which is declared public, otherwise it cannot be accessed outside of the file in which it is defined (it's basically unreachable).

 
code of conduct - report abuse