29

I'm at a complete loss here. I have a project on an external hard drive called LenseProject. Inside LenseProject, I have .idea, lib, Natives and SRC folders. I also have a number of text files for reading.

When I left work last night, this all worked fine. Coming in this morning, I'm met with:

Exception in thread "main" java.lang.ClassNotFoundException: QuadTest
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:188)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113) 

QuadTest being the main class.

Information that I think might be helpful:

  • If I comment out the imports, I get the appropriate error messages. (Cannot find symbol, etc).

  • I have 9 dependencies, located in lib\lwjgl-2.9.0\jar that are set up in Project Structure -> Libraries.

  • The module has LenseProject as the content root, and SRC as the source folder.

  • The language level is 7.0

  • I have the dependencies set to export in Project Structure -> Modules -> Dependencies.

  • In Compiler Output, I have it set to Use Module Compile Output Path, as Inherit Project Compile Output Path gave me "Cannot start compilation: The output path is not specified for module "LenseProject". Specify the output path in Configure Project.

  • I have VM option -Djava.library.path=Natives.

  • I can compile and run the program through command prompt no problem.

  • I was missing my configure options when I started it up this morning. I had to set the SDK again, and libraries.

5
  • You need to download dependencies first then add it to the project classpath.
    – Roman C
    May 31, 2013 at 13:00
  • I'm not sure what you mean. I have the dependencies in the lib folder.
    – Cereal
    May 31, 2013 at 13:09
  • 1
    Have your tried to invalidate caches. often help with sudden errors. File-> invalidate caches
    – M4tchB0X3r
    May 31, 2013 at 13:43
  • Have you had found a solution for this issue? I'm facing the same but three years later :) Mar 7, 2017 at 9:43
  • in 2020: a potential remedy, if using Gradle, is to edit your build.gradle and rebuild it
    – ExactaBox
    Aug 13, 2020 at 13:40

11 Answers 11

17

Open your Idea File --> Project Structure --> Modules ,and then choose problematic module,in the "Paths" tab change selected to "Use module compile output path ".

0
10

I ran into a similar issue while writing unit tests. Everything would work at the command line but failed in IntelliJ. IntelliJ would successfully compile but not run the test.

Then I ran across a post on IntelliJ's blog: http://blog.jetbrains.com/idea/2014/03/intellij-idea-13-1-released/

anet says:

March 21, 2014 at 12:20 pm

You may remove the existing junit dependency and allow IDEA to add JUnit library for your from scratch.

New junit doesn’t bundle hamcrest anymore but still depends on it on runtime.

Thanks, Anna

I removed JUnit from my project settings and let IntelliJ add it back. Then things worked fine.

0
5

I had similar issue. A new dependency was not being found when running tomcat. The problem was it wasn't being deployed to /WEB-INF/lib. After half a day banging my head on the desk I found this YouTube video that fixed it.

Essentially I needed to add the dependencies from module settings-> artifact->MyWar->Output Layout tab. Under available elements open your projects folder. If there are maven dependencies listed there, select them. Then right click->Put into /WEB-INF/lib

0
1

In my case, the problem was I reused the "out" directory for program output. I solved it by redirect the output to another folder.

0

I suggest confirming your Run Configuration as follows:

Toolbar: Run->Edit Configurations..., confirm your Configuration is correct.

enter image description here

Hope it helps.

0

I know its a bit old post but for me helped by going to Run-->Edit Configurations--> In Application Selected your main code file --> Configuration on the right panel. Checked "Use alternative JRE:" and selecting JDK folder called jre(.../Java/jdk.x.x.x_xx/jre). Apply and OK. I am really new with intelliJ but that solved my problem hope it helps someone.

0

My problem was, that all this renaming the project-structure, my Maven dependencies didn't mach.

After changing the maven dependencies in the pom file, it worked.

0

File -> Project Structrure -> Project. Change the Project Language level from "SDK default" to Actual version that you are using.

This is weird, but solves the problem.

0
0

Check your mainClassName

mainClassName = "com.xxx.xxxApplicationKt"

0

After bashing head into multiple times, the issue is resolved by downgrading the Junit version.

At the time of writing the latest junit version is 5.8.2. However, after downgrading the version to 5.7.2 in the pom.xml the test successfully Run.

Resolution 1 : Update Java, if you're using Java 8 check Java version with java -version if Java is added to Path(Windows)

From the Start Menu, and Java Folder, Check for Updates

Resolution 2 : Downgrade junit in pom.xml

Resolution 3 : Install the proper JDK latest version from Oracle link-windows not from Google suggested link

-3

Try going to Preferences -> Compiler and select Eclipse, rather than using javac.

3
  • So why are you telling Intellij to select the Eclipse compilers? The chances are, they won't be installed. And is it even an option to select them?
    – Stephen C
    May 2, 2016 at 23:27
  • @StephenC yes, it is an option. Check it out.
    – BAR
    May 13, 2016 at 15:28
  • 3
    OK ... so assuming that the Eclipse compilers are installed (a stretch!) ... >>why<< would changing the compilers fix what is essentially a runtime classpath problem?
    – Stephen C
    May 14, 2016 at 0:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.