Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij suddenly throwing ClassNotFoundException

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.

like image 914
Cereal Avatar asked May 31 '13 12:05

Cereal


People also ask

What causes ClassNotFoundException in Java?

ClassNotFoundException is a checked exception which occurs when an application tries to load a class through its fully-qualified name and can not find its definition on the classpath. This occurs mainly when trying to load classes using Class. forName(), ClassLoader. loadClass() or ClassLoader.

Is ClassNotFoundException a runtime exception?

ClassNotFoundException is a runtime exception that is thrown when an application tries to load a class at runtime using the Class. forName() or loadClass() or findSystemClass() methods ,and the class with specified name are not found in the classpath.


2 Answers

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

like image 167
刘新宇 Avatar answered Oct 14 '22 14: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

  • See more at: http://blog.jetbrains.com/idea/2014/03/intellij-idea-13-1-released/#sthash.2KNQuwZ5.dpuf

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

like image 39
TreverW Avatar answered Oct 14 '22 12:10

TreverW