Ask coding questions

← Back to all posts
Error Could not find or load main class
AndrewHann (0)

I keep getting Error: could not find or load main Class Main. This might be something simple I am just missing because of how late it is. Any help would be appreciated.
Thanks
P.S When I create a java project, it auto populates with class Main. In the Java Swing project, I typed in this information. I am not sure if that impacts the project.

Commentshotnewtop
AndrewHann (0)

I took one last look tonight...showInputDialog not showInputDialogue...that is what it was. Thanks again everyone for your help on this

RYANTADIPARTHI (3349)

The error i think is because you are not calling your class.

Maybe if you called it, it would work.

AndrewHann (0)

@RYANTADIPARTHI Thank you for your reply. I took what you said and tried to create the program again from scratch. The syntax all looks the same but this one runs. If you happen to see the difference between the two and can point it out to me I would apprecaite it. Thanks again.
https://repl.it/@AndrewHann/This-Is-a-Try

RYANTADIPARTHI (3349)

@AndrewHann it looks like it is working. So whats your main question for now?

AndrewHann (0)

Hi @RYANTADIPARTHI . No main question. I am just trying to figure out how I the same workflow on two different projects resulted in different outcomes. Each project has the exact same syntax however one works and one doesn't. I can live with it. I am just curious is all. I appreciate you replying back to me so quickly. Have a great evening. Thanks

RYANTADIPARTHI (3349)

@AndrewHann oh, ok, so it's probably because the main syntax gets full priority first as main.java, and the other if you imported it gets next, there should be a change if both needs to work. But one at a time though.

Coder100 (12532)

well now there's a new error:

Anyways just make sure your classes are like:

class Main

and not:

class JavaSwing

because your current file is called Main

AndrewHann (0)

Hi @Coder100 . Thanks for the quick reply. Again, its late so maybe I am missing something here. Just looking at what I have above, I thought I had this set up with Main as my current file ( top left hand corner Main.java) and I have public class Main which contains the main method.
Shouldn't the class name match the java file name?