Java Exception - NoDefClassFoundError

  • Context: Java 
  • Thread starter Thread starter rollcast
  • Start date Start date
  • Tags Tags
    Java
Click For Summary
SUMMARY

The discussion centers on the Java exception "NoClassDefFoundError," which occurs when the Java Virtual Machine (JVM) cannot find a class definition, specifically for the class named "temp." This error often arises due to incorrect file naming or directory structure, as Java requires precise adherence to naming conventions. Users are advised to consult system documentation for a basic "hello world" example and ensure that environment variables, particularly CLASSPATH, are correctly configured to resolve the issue.

PREREQUISITES
  • Understanding of Java programming and its class structure
  • Familiarity with the Java Virtual Machine (JVM) and its error handling
  • Knowledge of environment variables, specifically CLASSPATH
  • Experience with IDEs like Geany for Java development
NEXT STEPS
  • Review Java class naming conventions and directory structure
  • Learn how to configure the CLASSPATH environment variable in Java
  • Explore the Java documentation for basic programming examples
  • Investigate common Java exceptions and their troubleshooting methods
USEFUL FOR

Java developers, students learning Java programming, and anyone troubleshooting Java class loading issues will benefit from this discussion.

rollcast
Messages
403
Reaction score
0
I'm trying to run a java program I coded using geany but it would let me run it as it comes up with the following error message.

Code:
Exception in thread "main" java.lang.NoClassDefFoundError: temp
Caused by: java.lang.ClassNotFoundException: temp
	at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: temp. Program will exit.

So then I thought it may have been my bad coding but even when I copied a few example codes from wikipedia it still gave me the same error?

Thanks
A.
 
Technology news on Phys.org
It looks like you are missing a definition for a class named temp.
 
Java is different from most programming languages in that it is VERY fussy about what you call your program files, and the directory structure you put them in.

There should be a "hello world" type of example in the system documentation. Try that, and make sure you do EXACTLY what it tells you to do.

You might have to set up some environment variables (CLASSPATH, in particular) before anything works.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
39K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
7K
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
15K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 6 ·
Replies
6
Views
5K