openSUSE Forums > Archives > SF Archives > ARCHIVES - Programming & Scripting » Unable To Run My Java Class File

Go Back   openSUSE Forums > Archives > SF Archives > ARCHIVES - Programming & Scripting
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
  #1 (permalink)  
Old 04-Mar-2008, 06:40
tewemit
Guest
 
Posts: n/a
Default

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.
  #2 (permalink)  
Old 04-Mar-2008, 08:22
Berislav Kovacki
Guest
 
Posts: n/a
Default

Try starting it with:
Code:
$ java HelloWorldApp
You have to specify the name of the class that you want to start, not the name of the class file...
  #3 (permalink)  
Old 04-Mar-2008, 09:08
tewemit
Guest
 
Posts: n/a
Default

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.
  #4 (permalink)  
Old 05-Mar-2008, 19:30
AndrewTheArt
Guest
 
Posts: n/a
Default

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
  #5 (permalink)  
Old 06-Mar-2008, 05:55
tewemit
Guest
 
Posts: n/a
Default

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2