Java: Exception in thread main java.lang.NoClassDefFoundError
This tutorial explains a common error that beginning Java authors may experience.
- Exception in thread “main” java.lang.NoClassDefFoundError:
When trying to run a Java program, you may get this annoying error. I first got it when running our simple hello world program.
The error occurs because the classpath is not set up or referenced correctly.
Executing your program using the following command should correct the problem:
java -classpath . helloworld
In this command, helloworld is the name of your compiled class.
This tells Java that your classpath is your local directory.
View more articles by David Kirk
Follow the reactions below and share your own thoughts.