Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAVA "Error: Could not find or load main class main" - SOLVED in CMD (W10), add solution to atom-script #1470

Closed
createdbyjurand opened this issue Oct 29, 2017 · 8 comments

Comments

@createdbyjurand
Copy link

I made a test file "main.java":

--------------------------- start ---------------------------
import java.util.;
import java.lang.
;
import java.io.*;

class Test {
public static void main (String[] args) throws java.lang.Exception {
System.out.println("test");
}
}
--------------------------- end ---------------------------

I got an error:
"Error: Could not find or load main class main"

Solution 1 - filename should have the same name as class, so renaming file to Test.java can fix that.

but

Solution 2 - in Windows 10 x64 cmd.exe, when you run command "java -cp . Test" or java -classpath . Test" everything works, because it also looks in local directory.

If you add to classpath ".;" ( c:\Program Files\Java\jre1.8.0_152\lib\rt.jar;. ) in cmd.exe command "java Test" starts to run and everything is ok.

However in atom-script still throws error "Error: Could not find or load main class main".

Could you fix it?

@createdbyjurand createdbyjurand changed the title "Error: Could not find or load main class main" - SOLVED in CMD (W10), add solution to atom-script JAVA "Error: Could not find or load main class main" - SOLVED in CMD (W10), add solution to atom-script Oct 29, 2017
@rishabh0x00
Copy link

you need to make your main class public

@rushikeshmore
Copy link

Reinstall JDK

@Karan102pal
Copy link

Its already public!!!

@gitvivekgupta
Copy link

+1

Error: Could not find or load main class sun.applet.AppletViewer
Caused by: java.lang.ClassNotFoundException: sun.applet.AppletViewer

Process finished with exit code 1

@ghost
Copy link

ghost commented Apr 21, 2019

did every thing but still giving error "could not find or load main class"

@ADepic
Copy link

ADepic commented Mar 30, 2020

For me, java Testfile.java works in terminal.
However, this is the command that is run in script package (why?):
bash -c 'javac -J-Dfile.encoding=UTF-8 -sourcepath '/home/superuser/Desktop/java test_ folder structure' -d /tmp '/home/superuser/Desktop/java test_ folder structure/java test project/src/com/testproject/Testfile.java' && java -Dfile.encoding=UTF-8 -cp /tmp java test project/src/com/testproject.Testfile'

my current solution is to use the atom-python-run package and change the F5 command from python {file} to java {file}

@ADepic
Copy link

ADepic commented Mar 30, 2020

Edited the source code so that the command now is
java '/home/superuser/Desktop/java test_ folder structure/java test project/src/com/testproject/Testfile.java'

and it still gives me the error. Copying that exact command into the terminal does not give me that error. So what is the problem?

@aminya
Copy link
Member

aminya commented May 12, 2021

Should be fixed in #2470. Let me know if it is not.

@aminya aminya closed this as completed May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@Karan102pal @aminya @gitvivekgupta @ADepic @rishabh0x00 @createdbyjurand @rushikeshmore and others