Java Exception in thread main java.lang.NoClassDefFoundError:

  • Thread starter Thread starter tjaeger
  • Start date Start date
  • Tags Tags
    Thread
AI Thread 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).
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
2
Views
5K
Back
Top