tags:

views:

3704

answers:

4

I am getting this error when I include an opensource library that I had to compile from source. Now, all the suggestions on the web indicate that the code was compiled in one version and executed in another version (new on old). However, I only have one version of JRE on my system. If I run the commands:

$ javac -version
javac 1.5.0_18

$ java -version
java version "1.5.0_18"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_18-b02)
Java HotSpot(TM) Server VM (build 1.5.0_18-b02, mixed mode)

and check in Eclipse for the properties of the java library, I get 1.5.0_18

Therefore, I have to conclude something else, internal to a class itself, is throwing the exception?? Is that even possible?

A: 

Are you absolutely sure that there are no old .class files hanging around somewhere in that code?

Vinny
it is a pretty clean system and this is the only addition. is there any way to pin-point which class is clashing?
grmn.bob
Yup -- see above, but I was running mixed. Thanks Vinny for the support.
grmn.bob
You are welcome. Glad you got the fix. Be sure to 'accept' the correct answer
Vinny
A: 

Did you compile with Eclipse? It uses a different compiler (not javac). That should not result in this error (if everything is configured properly), but you can try to compile it with javac instead.

If that fixed the problem, try to see if Eclipse has some incorrect compiler settings. Specifically have it target Java 5.

Thilo
That is what I am learning. I am going to try building the two pieces the same way (cmd line and/or eclipse).
grmn.bob
Thanks Thilo, I have learned a lot today about Eclipse and Java and class versions. And a little about *ant* too.
grmn.bob
+1  A: 

Have you tried doing a full "clean" and then rebuild in Eclipse (Project->Clean...)?

Are you able to compile and run with "javac" and "java" straight from the command line? Does that work properly?

If you right click on your project, go to "Properties" and then go to "Java Build Path", are there any suspicious entries under any of the tabs? This is essentially your CLASSPATH.

In the Eclipse preferences, you may also want to double check the "Installed JREs" section in the "Java" section and make sure it matches what you think it should.

You definitely have either a stale .class file laying around somewhere or you're getting a compile-time/run-time mismatch in the versions of Java you're using.

Brent Nash
yes (full clean); have not tried it (project from cmd line); maybe/no (I removed entries from Eclipse "Java Build Path"); did that (JREs - that is where I got the version#).
grmn.bob
+7  A: 

I've learned that error messages like this are usually right. When it couldn't POSSIBLY (in your mind) be what the error being reported says, you go hunting for a problem in another area...only to find out hours later that the original error message was indeed right.

Since you're using Eclipse, I think Thilo has it right The most likely reason you are getting this message is because one of your projects is compiling 1.6 classes. It doesn't matter if you only have a 1.5 JRE on the system, because Eclipse has its own compiler (not javac), and only needs a 1.5 JRE to compile 1.6 classes. It may be weird, and a setting needs to be unchecked to allow this, but I just managed to do it.

For the project in question, check the Project Properties (usually Alt+Enter), Java Compiler section. Here's an image of a project configured to compile 1.6, but with only a 1.5 JRE.

Joshua McKinnon
Totally agree ... that is why I asked, in my comment, the question for ways to pin-point. I did not know of the Eclipse internal classes. The library was compiled on the command line with 'javac' and integrated into my Eclipse project. I will try compiling my project from the command line. You clearly have solved this problem in the past and your suggestions are fantastic.
grmn.bob
If you have the JDK (which has sources), you should be able to add some breakpoints in Eclipse and hopefully see what class it's attempting to load. The easiest way is probably a breakpoint in the constructor for UnsupportedClassVersionError (or an Eclipse Exception breakpoint, the 'J!' icon), then you can inspect how it got there.
Joshua McKinnon
OK. I found an expert in the building and he was able to point Eclipse to the same JRE as my command line. I then rebuilt against 1.6 and ran against 1.6 and it is all working. Obviously, I was wrong about not having anything but 1.5. He showed me where to look.Thanks for the help -- now I am on to my next problem! :)
grmn.bob
BTW - Joshua, I really appreciated the screen shot.
grmn.bob