Java Exception in thread main java.lang.NoClassDefFoundError:

  • Thread starter Thread starter tjaeger
  • Start date Start date
  • Tags Tags
    Thread
Click For Summary
The discussion revolves around resolving the "NoClassDefFoundError" and "ClassNotFoundException" errors encountered while compiling and running Java programs in SSH Secure Shell. The user initially attempted to compile a simple "Hello World" program but faced issues due to incorrect commands. Key solutions provided include ensuring the correct compilation command is used: 'javac HelloWorld.java' to create the class file. After compilation, the program should be run with 'java -classpath . HelloWorld', which specifies the current directory as the classpath. Additionally, it's important to verify that the .bash_profile is correctly configured with the appropriate Java version and classpath settings to avoid any runtime issues.
tjaeger
Messages
7
Reaction score
0
Exception in thread "main" java.lang.NoClassDefFoundError:

I was getting this error trying to compile some java programs in SSH Secure Shell. Then I made a simple "Hello World" program in my home directory to see if it would compile by typing 'java HelloWorld' but all I got was:

Caused by: java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

I looked it up on google and a website said to try compiling by typing
'java -classpath.HelloWorld' but that gave me the error:

Unrecognized option: -classpath.HelloWorld
Could not create the Java virtual machine.

I haven't used Secure Shell in a long time, any help is appreciated.
 
Technology news on Phys.org


You have to type "javac HelloWorld.java," assuming you have your .bash_profile set up correctly. Otherwise, it's trying to run a program that doesn't exist.

Also, make sure $HOME/.bash_profile has something like this in it:

JAVADIR="j2re1.6.2_xx" (note you must ensure that the proper version and release number are coded here)
export JAVADIR
PATH=/usr/java/$JAVADIR/bin:$PATH:$HOME/bin:/sbin
export PATH
CLASSPATH=/usr/java/$JAVADIR/lib:/usr/NetRexx/runlib/NetRexxR.jar
export CLASSPATH
 


Try this...

compile with this command

javac [javafilename].java

then after u get the classfile (the bytecode)

run using :

java -classpath . [javafilename]

this will specify that the classpath is the current directory ( . ----> refers current working directory).
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 2 ·
Replies
2
Views
5K