LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-23-2006, 11:16 PM   #16
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65

M$ISBS

Where did you get your J2SE SDK from?

I recommend getting it from Sun's Java page and click on Java SE on the right-hand side, and it'll take you to a page with different Java SE "bundles"...for everyday Java, scroll down the list, and look for "JDK 5.0 Update 9" (it's the fourth item down), and then get the "Linux self-extracting file" (jdk-1_5_0_09-linux-i586.bin). Installation instructions are here.

When you run the binary installer (don't forget to "chmod +x jdk-1_5_0_09-linux-i586.bin", and run, as root), it will install to "/usr/java/jdk1.5.0_09/". (at least, that's where it went, by default, for me)

If you are using Sun's J2SE JDK, just try removing it, and reinstalling it.
 
Old 11-24-2006, 12:34 AM   #17
Sepero
Member
 
Registered: Jul 2004
Location: Tampa, Florida, USA
Distribution: Ubuntu
Posts: 734
Blog Entries: 1

Rep: Reputation: 33
Quote:
Originally Posted by Sepero
"Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/java"

Interesting error message. I remember getting garbage messages like this whenever I would try to create .jar files.

I haven't programmed Java in a couple years now, but you might want to try putting "public" on your class:
public class HelloWorldApp {
Did you try this??
 
Old 11-24-2006, 12:36 AM   #18
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
has any others ran the exact program he has and does it run fine? im in windows but it works fine here.
 
Old 11-24-2006, 12:45 AM   #19
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
This problem:
Code:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
is due to a class compiled with a JDK more recent than the JRE.

You definitely need to tell what is installed on your box, what is your PATH when you compile and when you run the program.

Output of "which java" and "which javac" would help.
 
Old 11-24-2006, 01:06 AM   #20
Sepero
Member
 
Registered: Jul 2004
Location: Tampa, Florida, USA
Distribution: Ubuntu
Posts: 734
Blog Entries: 1

Rep: Reputation: 33
Quote:
Originally Posted by jlliagre
This problem:
Code:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
is due to a class compiled with a JDK more recent than the JRE.
In theory, you seem to make logical sense with this statement. But upon further review, there is NO WAY IN HECK that is the problem.

This is a simple "Hello World" program! JRE's back to 2.0 should be able to run this, no matter how new the SDK is.
 
Old 11-24-2006, 03:25 AM   #21
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by Sepero
In theory, you seem to make logical sense with this statement. But upon further review, there is NO WAY IN HECK that is the problem.
This is very likely the problem, like it or not.
Quote:
This is a simple "Hello World" program! JRE's back to 2.0 should be able to run this, no matter how new the SDK is.
Nope, unless the proper option is used at compilation time, an older JVM can't run newer classes, by design.
 
Old 11-24-2006, 10:18 AM   #22
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Code:
#!/usr/bin/clisp
(format t "~%Hello, World!~%")
Java's been a good source of frustration for me. I've resorted to other languages, like Lisp, but I still find a use for Java every now and then.

M$ISBS, I heavily recommend using Sun's J2SE JDK, and in ~/.bashrc add these lines:
Code:
PATH=$PATH:/usr/java/jdk1.5.0_09/bin
export PATH
 
Old 11-24-2006, 12:45 PM   #23
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hello again, M$ISBS! If things still aren't working for you, please try this:
Quote:
1. If you haven't already done so, please download and install the Sun JDK per these instructions:
http://java.sun.com/j2se/1.5.0/install-linux.html
Please post back if you have any problems or questions
<= IT SOUNDS LIKE THIS IS ALREADY DONE AND WORKING

2. Go to your "working directory"
EXAMPLE:
mkdir ~/work
cd ~/work

3. Create your "hello world". Let's just call it "hello.java" this time:
vi hello.java
Code:
public class hello {
  public static void main (String[] args) {
    System.out.println ("hello java!");
  }
}
4. Compile it and verify you got a class file:
Quote:
javac -version hello.java
javac 1.5.0_07
Quote:
ls -l
total 8
-rw-r--r-- 1 paulsm users 415 2006-11-24 10:41 hello.class
-rw-r--r-- 1 paulsm users 112 2006-11-24 10:41 hello.java
5. Make sure the Java runtime version matches your compiler version:
Quote:
java -version
java version "1.5.0_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)
6. Finally, try running it ... IN THE CURRENT DIRECTORY:
Quote:
java hello
hello java!
Please post back your results - a lot of people are interested in the outcome !

'Hope that helps .. PSM
 
Old 12-12-2006, 05:11 PM   #24
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
Ive tried the above suggestions and I still get an unsupported class version error. Java is working and installed from the sun website and java and, the compiler should be the same version becuase im pretty sure jre gets installed along with the JDK.
 
Old 12-12-2006, 05:21 PM   #25
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Is there really any reason for you to keep a secret from us outputs like "java -version", "javac" and "which java"? Because if you have posted that from the beginning we should know for sure if java is correctly installed as it should and that both the java sdk and re are the same. Some distributions ship with a replacement for java sdk/re called gcj and that is a very common problem in here lately. Even if you've installed java correctly but did not configured your path, you might still be running the gcj instead of Sun's Java RE (which I am quite positive you have, since you did not include java on your path according to this post number 14 here.

Just post the output of the above commands so we can make sure if that is your actual problem or if your problem lies somewhere else...

Last edited by Mega Man X; 12-13-2006 at 12:09 AM.
 
Old 12-12-2006, 05:29 PM   #26
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
Ok,
java -version
java version "1.5.0_09"
mixed mode, sharing.

which javac
/home/prog/jdk1.6.0/bin/javac

which java
/usr/lib/java/bin/java

the directory is different now because I am working on a different computer but have the same exact error.
 
Old 12-12-2006, 08:07 PM   #27
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
Does this mean that I have different versions of JRE and JDK?
 
Old 12-13-2006, 12:03 AM   #28
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
yes. You have Java 6 SDK (newer) and Java 5 RE (older). Try to compile and run like this:

/home/prog/jdk1.6.0/bin/javac /path to your program/HelloWorldApp.java
/home/prog/jdk1.6.0/bin/java /path to your program/HelloWorldApp

Last edited by Mega Man X; 12-13-2006 at 12:10 AM.
 
Old 12-13-2006, 12:38 AM   #29
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 52
Quote:
Originally Posted by M$ISBS
nadroj:
Yes, thats exactly how I am doing it.

indienick:
I tried that and I get the same error messages as before.

I just tried something different. I logged in as root and tried it, but I had to put ./ in front of javac and java, the long list of errors went away but I still get:

"Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/java"

java -jar HelloWorldApp.jar assuming that you defined the main-class in te jar manifest.

java HelloWorldApp if the HellWorld app is not in a package!?
 
Old 12-13-2006, 12:31 PM   #30
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
Thanks for all the help. Got it working.

Last edited by M$ISBS; 12-13-2006 at 01:44 PM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java question Jongi SUSE / openSUSE 2 09-19-2005 01:07 PM
Java Question k1ll3r_x Programming 2 08-20-2005 08:10 PM
Java question biojayc Linux - Newbie 8 03-22-2005 03:42 PM
java question zaicheke Programming 5 02-15-2005 12:40 PM
Java Question k1ll3r_x Programming 3 11-13-2004 04:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration