error to find main class

Answered

Error: Could not find or load main class sample.Main, i am getting this error message while running my code, how can i solve it?

 

0
6 comments
Avatar
Yaroslav Bedrov

Hello,

Could you please add more details about you project? Do you use build systems (Maven, Gradle)? Does it compile/run fine from command line? Is it possible to provide project example or screenshots with project structure?

 

0

I have the same issue. Using version

IntelliJ IDEA 2018.2.1 (Ultimate Edition)
Build #IU-182.3911.36, built on August 7, 2018
JRE: 1.8.0_152-release-1248-b8 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

File, New Project, select Java, Next. Check 'Create project from template', select Command Line App, next. 

The new app is created, now press run. 

 

"C:\Program Files\Java\jdk1.8.0_161\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.1\lib\idea_rt.jar=11036:C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_161\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\rt.jar" com.test.Main
Error: Could not find or load main class com.test.Main

Process finished with exit code 1

0

@Chris Davies could you please provide a project example?

1

How can I upload it here?

0

the best way is to put it on GitHub.

0

The good news is the problem is resolved. The bad news is that I have no idea how. 

My machine did a windows update overnight which broke my IntelliJ installation, basically it blew away the registry entries for the IntelliJ installation. As a result I had to perform a new install of IntelliJ and now the I no longer receive the 'Error: Could not find or load main class sample.Main' error. The only thing I notice is that the 'out' directory is now appearing in my project, so I suspect the build was not creating the class file for some reason but I would have expected a build error.

0

Please sign in to leave a comment.