"Cannot find or load main class" no output files
Greetings!
We received a few simple Java files from our Professor to be edited by us (getting more complex each lecture). I tried loading them into IntelliJ however I cannot get this thing to run. He just sent the 2 files so I put them in proper places according to the usual Java-structure. Setup is as follows:
PorjectRoot
|--- src
|--- main
|-- Task03_audio.java
|-- Utility.java
That's it.
It's a very simple JavaFX application. Both .java files have their classes named exactly like the filename. The package is named exactly "main".
The other steps I already did are:
- Manually set "src" to be the "source root" in Project Settings
- Manually set "out" to be the output directory in Project Settings
- Set the SDK to my JDK directory and target language to 10 (also tried 8)
- Created a Run Configuration, declaring "main.Task03_audio" as main class (class contains main() obviously) and the Project Root as working directory (also tried "src" and "out")
Everytime I try to run it "Cannot find or load main class" comes up, followed by a "java.lang.ClassNotFoundException: main.Task03_audio". The "out" folder contains nothing afterwards, so I'm not even sure IntelliJ places the .class files properly there. Compiling the project manually on command line by going into "src" and invoking "javac main/*" and then "java main.Task03_audio" works.
I'm pretty sure I'm missing something really obvious here as running such a simple project cannot possibly fail that hard.
What are the necessary steps to get a few simple Java files to run in IntelliJ? No additional dependencies besides default libs required.
The question might sound pretty dumb, but any advice or hint is greatly appreciated, as I already went through countless SO-Thread suggesting the obvious stuff (which usually does the job).
Kind regards
Please sign in to leave a comment.
Please see https://stackoverflow.com/a/42660624/104891 . Share the complete project if the issue persists: https://intellij-support.jetbrains.com/hc/articles/206869619.
Thanks for the response.
I fiddled around a bit, cleared my Java JDK installation and reinstalled only Java 8 to avoid any mix-ups with JAVA_HOME or something.
However, I just tried to create a JavaFX project from scratch using the IntelliJ Wizard. Without any modification it didn't run either responding with the same error as before, so I suspect the project not being on the classpath or something, despite the project settings clearly stating that the "Module Out" directory is included in it and other settings just inherit it (I checked those settings but they didn't work from the beginning).
The output line of the Terminal when trying to run the Run Configuration is as follows:
/usr/lib/jvm/java-8-oracle/bin/java "-javaagent:/home/NAME/Tools/IntelliJ IDEA/lib/idea_rt.jar=42127:/home/NAME/Tools/IntelliJ IDEA/bin" -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/nashorn.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-8-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfxswt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/management-agent.jar:/usr/lib/jvm/java-8-oracle/jre/lib/plugin.jar:/usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar sample.Main
Error: Main class sample.Main cannot be found or loaded. <Translated from my actual error as it is in another language>
Other students get this to work (also in IntelliJ) easily, so something with my environment is wrong, obviously.
I don't see the project output directory after -classpath.
Please share the complete sample project to reproduce, see https://stackoverflow.com/help/mcve.
Uploaded an entire Sample Project to GitHub: https://github.com/GxTruth/SampleProject
I cloned it and verified, that the same error occurs.
What really bothers me is, that the project dir is not included in the classpath but the Project Settings clearly state:
Project --> Project Compiler Output: This is the project's absolute path with a trailling /out (this directory never appears).
Project --> Project SDK & Language Leven: Both set to Java version 8.
Modules --> SampleProject --> Paths: Inherit Project Compile Output Path
Meanwhile the Run Configuration yields the "SampleProject" Module at "Use Classpath of Module".
Edit: I just tried adding the "out" directory manually as a dependency for "Class Files" and "JAR directory". Didn't work either.
Please also share IDE logs (idea.log and build.log with debug info enabled): https://intellij-support.jetbrains.com/hc/articles/207241085.
Your project builds and runs on my system.
I just suspected that it would run on another machine. I added the Logs to the GitHub Repo (https://github.com/GxTruth/SampleProject/blob/master/logs-20190306-115149.zip). Just replaced my actual username with "MYNAME".
As I created the logs, I did the following:
Thanks for your help so far!
Your IDE installation seems to be corrupted. Try to reinstall from http://www.jetbrains.com/idea/download/index.html.
Make sure to unpack into the empty directory and not on the top of the existing version.
Error in the log:
This fixed the problem.
Holy Lord, finally.
Thank you very much for going through my logs and pointing out this error!