|
||||||
| Forums FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| ARCHIVES - Programming & Scripting A place to discuss website design, programming, shell scripts, etc |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi guys, Here is my problem. Hope it is simple for you. I wrote a simple Hello world java program. Then when i compile it,it goes well. But when I use "java HelloWorldApp.class" command to run it, it displays: "Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/class." Farther more, i tried to see the versions of the jre and the jdk using the commands: 'javac -version' and 'java -version'. then i made sure thay are different versions, jre1.5 and jdk1.6, but not sure if this is the the problem.
So can any one help me here. Thank you in advance. Tewemit. |
|
|||
|
Try starting it with:
Code:
$ java HelloWorldApp |
|
|||
|
Thank you for your help but when i run the command "java HelloWorldApp", i got the following error report, some thing related to versions;
------------------------------------------------------------ Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java :620) at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:124) at java.net.URLClassLoader.defineClass(URLClassLoader .java:260) at java.net.URLClassLoader.access$100(URLClassLoader. java:56) at java.net.URLClassLoader$1.run(URLClassLoader.java: 195) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06) at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:268) at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51) at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319) ----------------------------------------------------------------- when i run 'javac -version', i get javac 1.6.0_04 and when i run 'java -version', i get: java version "1.5.0_14" Java 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03) Java HotSpot Client VM (build 1.5.0_14-b03, mixed mode) thnks. tewemit. |
|
|||
|
You're trying to run a class file compiled with the 1.6 JDK platform using the Java 1.5 JRE. You can generally run older class files with newer JRE's but you definitely can't run newer class files with older JRE's.
Upgrade your JRE to 1.6 (you can do it manually from the Java website) or recompile the class file into 1.5 bytecode. I saw do it manually because I don't see Java 1.6 in the repositories. http://www.java.com/en/download/manual.jsp |
|
|||
|
Thank you guys but still i have some thing wrong. I downloaded jre1.6.0_05 and installed it in /usr/local/src/ directory and modified my env variable,PATH, to include the new jre bin directory. But still the default jre with jvm is the former one, not updated. I don't know how to update it. Is there any command to start updating. Or shall i remove the former jre version? I think the directory the system is referring is /usr/lib/jvm/jre/bin because all the jre's and jvm's are in this dir. For more information here are what i did:
echo $PATH gives me /opt/kde3/bin:/home/tewe/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin:/usr/local/src/jdk1.6.0_04/bin/:/usr/local/src/jre1.6.0_05/bin jre1.6 i installed is in /usr/local/src/ jre1.5 is in /usr/lib/jvm/bin/ the alljava.sh file i modified is like this: __libdir=lib if [ -x /usr/lib64/jvm/java ] || [ -x /usr/lib64/jvm/jre ] ; then __libdir=lib64 fi if [ -x /usr/$__libdir/jvm/java/bin/java ] || [ -x /usr/$__libdir/jvm/java/bin/jre ] ; then export JAVA_BINDIR=/usr/$__libdir/jvm/java/bin export JAVA_ROOT=/usr/$__libdir/jvm/java export JAVA_HOME=/usr/$__libdir/jvm/java if [ -x /usr/$__libdir/jvm/java/jre/bin/java ] ; then export JRE_HOME=/usr/$__libdir/jvm/java/jre else export JRE_HOME=/usr/$__libdir/jvm/java fi unset JDK_HOME unset SDK_HOME if [ -x /usr/$__libdir/jvm/java/bin/javac ] ; then # it is development kit if [ -x /usr/$__libdir/jvm/java/bin/jre ] ; then export JDK_HOME=/usr/$__libdir/jvm/java else export JDK_HOME=/usr/$__libdir/jvm/java export SDK_HOME=/usr/$__libdir/jvm/java fi fi else if [ -x /usr/$__libdir/jvm/jre/bin/java ] ; then # it is IBMJava2-JRE or SunJava2-JRE #export PATH=$PATH:/usr/$_libdir/jvm/jre/bin export PATH=/usr/local/src/jdk1.6.0_04/bin:$PATH #export JAVA_BINDIR=/usr/$__libdir/jvm/jre/bin export JAVA_BINDER=/usr/local/src/jdk1.6.0_04/jre/bin export JAVA_ROOT=/usr/$__libdir/jvm/jre #export JAVA_HOME=/usr/$__libdir/jvm/jre export JAVA_HOME=/usr/local/src/jdk1.6.0_04 #export JRE_HOME=/usr/$__libdir/jvm/jre export JRE_HOME=/usr/local/src/jre1.6.0_05 unset JDK_HOME unset SDK_HOME fi fi unset __libdir So, i want to know what is wrong. |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|