UnsupportedClassVersionError

I have installed jdk1.5.0. Why am I getting an UnsupportedClassVersionError when I try to run a simple java app? The code is:

import java.io.*;

public class zxc {

  public static void main(String[] args) {

     System.out.println("No Answer!");
  }
}

Any thoughts?
ipaman
ipamanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Make sure you're running against 1.5 JRE and not lower
0
ipamanAuthor Commented:
I have the jdk1.5 and the jre1.5 installed.
JAVA_HOME is set to jdk1.5.0
CLASSPATH has jdk1.5.0\*

Do I need to have the jre1.5.0 somewhere in the classpath?

ipaman
0
CEHJCommented:
You need to have java.exe (1.5) on your PATH

Add this line

System.out.println(System.getProperty("java.runtime.version"));

and then recompile with

javac -source 1.5 -target 1.4 zxc.java

and it'll tell you what runtime you're using
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

kiranhkCommented:
no you dont need to have jre1.5. it comes with JDK1.5
do java -version and see if u r using the JDK 1.5 or not.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
>>You need to have java.exe (1.5) on your PATH

Easiest to add

%JAVA_HOME%\bin

to your PATH. Make sure no other version there if you want clean separation
0
CEHJCommented:
>>no you dont need to have jre1.5. it comes with JDK1.5

What i'm getting at is that java.exe should be 1.5. You may have a < 1.5 JRE in the PATH
0
ipamanAuthor Commented:
CEHJ,
Running <javac -source 1.5 -target 1.4 zxc.java> didn't tell me much except that I had a problem. Maybe it is just my environment, who knows.

kiranhk,
I found out that I was running 1.3.1 which was added to my path from my Oracle 9.2.x install. I knew Oracle used this version of Java but didn't realize it tried to make everyone use that version.
The solution was to put jdk1.5.0\bin and jdk1.5.0\lib before any Oracle\jdk stuff in my path. When I tried to execute it found the version of java that Oracle was using.

Thanks,
ipaman
0
kiranhkCommented:
Good then.
I would suggest having a bat file which will set the environment for the particular requirement of the application so that u wont run into problems like these again when working with multiple applications requiring multiple JRE/JDK. This way u can have control over which JRE ur application need rather than changing the System variable everytime.

Thats how i manage my development.

Thanks
0
ipamanAuthor Commented:
kiranhk,

Can you supply an example bat file?
Thanks,
ipaman
0
kiranhkCommented:
save this something like setEnv.bat or whatever name u want


set path=D:\j2sdk1.4.2_05\bin;%path%  (here according to your application need have the %PATH% changed)
set classpath=D:\DryLoop-LSMSAdptrs\testcode\jars\lm.jar;%classpath%
0
CEHJCommented:
>>Running <javac -source 1.5 -target 1.4 zxc.java> didn't tell me much except that I had a problem

Well it tells you what version you're running, which *is* the problem

>>The solution was to put jdk1.5.0\bin and jdk1.5.0\lib before any Oracle\jdk stuff in my path

I told you that earlier:

>>
Easiest to add

%JAVA_HOME%\bin

to your PATH. Make sure no other version there if you want clean separation
>>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.