Why is the exception in the "main" thread java.lang.NoClassDefFoundError :?

I run my software through Eclipse. Everything was fine yesterday. I have not made changes to the code, but today, when I try to run it again, I get the following error messages:

Exception in thread "main" java.lang.NoClassDefFoundError: coloredtrails/CTListener at test.DemoPlayer1.createAndShowGUI(DemoPlayer1.java:23) at test.DemoPlayer1.main(DemoPlayer1.java:39) Caused by: java.lang.ClassNotFoundException: coloredtrails.CTListener at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 2 more 

Why doesn't he see the class? What could be the reason for this? How can i solve the problem?

+7
source share
2 answers

A NoClassDefFoundError (almost) always means that your class path is wrong. Make sure your class path includes the base directory of the coloredtrails package. (Of course, also make sure that the coloredtrails\CTListener.class file coloredtrails\CTListener.class exists).

When launched from the command line:

You can set the class path by setting the CLASSPATH environment variable or by specifying it using the -cp or -classpath on the command line when your program starts. For example:

 java -cp C:\MyProject\classes coloredtrails.CTListener 

edit - If you look at the stack trace and see the URLClassLoader , it seems to me that you are trying to run a Java applet. To find out how to properly deploy applets to find all the classes an applet needs, see this tutorial: Deploying an applet .

+9
source

Sometimes my Eclipse (Indigo on MacOSX) does this, especially if I make changes (deleting files, moving them) to the project structure directly on the file system.

Basically, eclipse can no longer find the source folder, so it does not compile the source code, but tries to run it anyway (all without warning or a link to the problem).

To fix this, delete the original folder from the build path (= right-click the src folder in the project in the package explorer, then select “Build-path-> Remove from Build-path.” Then add it again (= right-click folder in the project in the package explorer and select “Add to build-path"). This will again make the src folder "visible" to the compiler and fix the problem.

+6
source

All Articles