+ 2

How can I run this program?

https://code.sololearn.com/c9iIt9aJJf07/?ref=app I had tried to run this program on BlueJ, but all my efforts were in vain. Then I downloaded Eclipse and tried to run it. I was not familiar with "modules" of Eclipse, so I had a hard time running it. Then I ran configuration as Java application. Then it said that there is a problem in "public static void main(String[] args)." Then I ran the program in Command Prompt by setting an environment variable and writing "javac" and "java" commands, but the same problem appeared of the main method stating that "Could not find or load the main method." How can I resolve this issue? Which IDE should I use? [Edited: "Thoq!" answered that we should name the file the same class name in which we had mentioned the main() method (In my case, "Pro_Atransport.java"). I am thanking "Thoq!" for giving time for the answer.]

22nd Sep 2019, 4:23 AM
GiantJupiter
GiantJupiter - avatar
7 Answers
+ 2
Try it with the name of the class where your main method is in. And it would be even better to have one file per class.
22nd Sep 2019, 4:40 AM
Thoq!
Thoq! - avatar
+ 1
You can only have one PUBLIC class per file and the name of the file has to be the same as that class. To keep your code organized you usually avoid having more than one class per file but as long as there is only one public class it would still be valid.
22nd Sep 2019, 4:51 AM
Thoq!
Thoq! - avatar
+ 1
Yes, you actually have to if you want it to work.
22nd Sep 2019, 5:04 AM
Thoq!
Thoq! - avatar
0
How did you name your file?
22nd Sep 2019, 4:33 AM
Thoq!
Thoq! - avatar
0
I named it as Atransport.java.
22nd Sep 2019, 4:35 AM
GiantJupiter
GiantJupiter - avatar
0
Meanwhile, can I name the file as "Pro_Atransport?"
22nd Sep 2019, 4:58 AM
GiantJupiter
GiantJupiter - avatar
0
Thank you very much, "Thoq!"
22nd Sep 2019, 5:05 AM
GiantJupiter
GiantJupiter - avatar