I recently finished a project in Eclipse and it ran without a problem. Then recently I imported a new assignment to work on for class, but when I did my old project all of a sudden had a x on its icon. I looked through the code, nothing had been changed, but it threw this error in the console:
java.lang.UnsupportedClassVersionError
at java.lang.ClassLoader.defineClass1(Native Method)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:685)
And others. Is this possibly due to the version of java being used or something else?
An UnsupportedClassVersionError is thrown when you use a higher JDK version to compile than when you try to run the program. For example, you compile Program.java using JDK1.7 but then attempt to run using JDK1.6. I am guessing that upon importing the new assignment for your class, you unknowingly adopted to use the JDK that the imported project was compiled in.
I suggest going to Eclipse Preferences and taking a look at your installed JRE's to make sure everything is okay and also to look at the projects Properties and looking at its Build Path. In general, make you you are using a version to run in that is at LEAST what you used to compile it. If you chose a higher version everything will still be okay.
EDIT:
Here is a link for more information on the matter and where I had originally read about this. I knew I had saved the link somewhere.
http://javarevisited.blogspot.com/2011/07/javalangunsupportedclassversionerror.html
Related
I am currently taking a class that requires me to use code created by the professor, but I've run into an issue. Whenever I try to run code that uses the professor's code, i get the following message:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: cs/comsc331/ppm/PPM has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0
I know what's causing this, as it tells me - my Java needs to be updated. However, when I go to do so, both Eclipse and the Java Control Panel tell me that I'm all set with the most recent version. I went looking, and on java.com it told me to download Version 8 Update 241, which I did, but nothing changed. When I started looking online for solutions, I came across a post that briefly mentioned that Eclipse would not run with a more recent Java on my system then Java 8.
It seems that I'm at an impasse - I either need a way to update Java without breaking my setup (I tried downloading a more recent version than Java 8 and Eclipse wouldn't start), or I need a way to run newer code on my older system, potentially by recompiling it myself (I tried doing this once and I couldn't figure it out so I could use some advice if this is the best way forward). If I have to recompile the code myself that's okay as there aren't a huge amount of files, but the more efficient the method, the better.
Updating to a newer OS is not an option (if that would even help) because when I've tried to do so in the past, my laptop had to be completely reset (something about it being to hold to handle the new way that files were being done? the explanation I received was unclear).
In the super short term, I've just been straight up copying the code into new files and compiling it on my own, but my professor wants us to work within the existing packages, so that is a bandaid more than anything else. Long term, I need a new laptop that can be fully updated (I got my current one in 2015) but I would assume that there's a more reasonable solution out there.
Thanks!
Error: A JNI error has occurred, please check your installation and try again.
Eclipse states: test has been compiled by a more recent version of the Java Runtime (class file version 56.0), this version of the Java Runtime only recognizes class file versions up to 52.0.
I had the problem referenced at this question: "Could not find or load main class" while trying to use JavaFX in Eclipse When using JDK13 and JavaFX13. All solutions pointed to downgrading to Java 8.
I installed Java 8, updated the build path, and it built fine. But now I get the error I am using Eclipse 2019-06 (4.12.0), JavaFX13, and JDK 1.8.0_231.
I researched the answer but the two questions that come didn't help. One was for an IntellJ solution and the other had a package I am unfamiliar with, and the error had to do with that package.
I simply don't know how to correct the build path or dependencies to fix this issue. It appears I need a lower version of the JVM, but cannot seem to locate it. Am I right, or can you please help?
Well, I have dropped back to JDK 8 and the built in JavaFX. Despite my best efforts, I cannot get JDK13 and JavaFX 13 to work without receiving the error "Could not find or load main class" (see link in post). Since there is no solution to that problem yet that works for me, I can bypass my error on this request all together and just use much older packages.
I've started encountering some weird exceptions trying to use the GWT designer. I'm on Ubuntu if it matters, GWT 2.4.0, Java 1.6.0_20 x64
When I use the designer, a previously used DisclosurePanel shows up in a pink box indicating. When viewing the details, it indicates a NoClassDefFound error. This makes no sense because in the code editor, the class is visible and compiles without error.
Secondly, I am unable to drop a CellTable instance on the designer. Even with the most basic T = java.lang.Object, the error comes back indicating an IllegalArgumentException : "Unable to find 'columns' in class com.google.gwt.user.client.UI.HTML.
This was working yesterday with the designer, but all of a sudden has entered the crapper. I tried reinstalling the GWT plugins, and even using a new eclipse install with fresh GWT plugins installed, but to no avail. Does anyone know the source of these errors and how to remedy them?
Alright, it seems that the other day I synced up my build machine for the fisrt time and had a different version of java installed on my dev machine. OpenJDK 1.6.0_20 (Iced Tea 1.9), vs Java SE 1.6.0_35.
Since this java was in my /usr/bin which was earlier in my PATH envi var than my 1.6.0_35 build that was at the end of the PATH, it was using hte older 0_20 version. I'm guessing the GWT designer was built with something closer to 1.6.0_35 than 1.6.0_20, and was causing conflicts as implied here.:
Start by checking your Eclipse ".log" file (found in your /.metadata directory). If the error references one of your classes or methods, check that your classpath properly references the class you are trying to use. Also check that your class is properly compiled (no red X's) and that a .class file exists in your projects /bin directory. A mismatch between the JDK used to compile your code and the JVM used to run Eclipse can also manifest itself as a NoClassDefFoundError problem. For example, if you compile your code using JDK 1.5 or 1.6 and then run your Eclipse using a 1.4 or 1.5 JVM, you can have this problem. If the error refers to a custom widget, you should also check that your component does not trigger an exception during its initialization (which can manifest itself as a NoClassDefFoundError). Try refreshing and cleaning your project using the Project > Clean... or Project > Build Project commands. If that does not help, send a test case to support.
My problem started the other day when I tried to run a jar file that was compiled in java 1.6 from a friend. I then got:
java.lang.NoClassDefFoundError
Since I was only using java 1.5 obviously. So I updated using the system update. This did not help and when I ran:
java -version
in the terminal it still said I had java 1.5. I then saw on the internet that there was an "java SE update 4" on apples download page available. I downloaded and installed this file but it still wouldn't work. I gave up and decided to go back to my programming in eclipse. When I tried to compile and run my application in eclipse I now recieved the same error java.lang.NoClassDefFoundError and it wouldnt let me proceed. I tried right clicking the project and viewing the properties but it wouldnt let me, just gave me another error. I figured I might messed something up when I installed the new java version so I tried reinstalling eclipse but it still gave me the same error. I tried creating a new workspace but that wouldnt help either. I then figured I would try to compile throught the terminal using:
javac main.java
java main
But I still get the same error. I went in under systems settings and diabled "java 1.6" and i tried creating new projects with both javaSE-5 and javaSE-6 but it just wont work. My thoughts now is if it has something to do with eclipse not being able to access the bin & src directories in the project directory but that should work if i reinstalled it? I also saw someone mention setting the classpath in os x but I don't know. I would really need some help solving this issue since a lot of my work rely on eclipse working. I would rather not have to reinstall the whole OS just because of this but if I can't get it to work I guess there is no other alternative.
Best Regards
Jonas Kristensson
"Reinstall the whole OS"? Good lord, no.
Your problems have nothing to do with the version of Java. You don't understand how CLASSPATH works.
The class you were trying to run wasn't on the CLASSPATH. If your friend gave you a JAR, you need to add it to your CLASSPATH and use the fully-resolved class name to run it.
A word of advice for your future mental health: When you have problems, don't assume the worst and jump to extreme measures. Try the simple solutions first.
I tried to run a jar file that was compiled in java 1.6 from a friend. ... Since I was only using java 1.5 obviously
Note that if this was really the case you'd get a java.lang.UnsupportedClassVersionError, since Java 5 can't run classes compiled for Java 6 (it might be able to do so, but the class files say "I'm Java 6+" (class version 50) and thus Java 5 would just refuse to run it (max class version in Java 5 would be 49).
Try to compile with
javac -source 1.5 target 1.5 .....
I have a 3rd party JAR file that is compiled using Java 1.4. Is there a tool that can make the jar file compatible with Java 1.6? (Something like 'retrotranslator' but what does the reverse of it).
I tried decompiling the class files and re compile them in 1.6 but it fails.
Here is the issue:
My project uses 'rsadapter.jar' for was 5.1 and I had my project setup in Eclipse 2.0 + JDK 1.4 and it used to work fine. Now, I have migrated to Java 1.6 and Eclipse Ganymede (as per the requirements) and the same project (exactly same setup) started complaining about the missing class files in the 'rsadapter.jar'. I put the JAR in classpath explicitly too but it still could not load the classes. Then I changed the Java Compiler version to 1.4 and it started working.
Regards,
- Ashish
Classes compiled by JDK 1.4 should be usable in a Java 6 runtime as-is. If you have actually encountered a problem, please describe it.
Update: I can only reproduce this with types in the "default" package (that is, not in a package). Are the classes you are trying to use in the default package? Also, this happens to me regardless of the JDK version used to compile.
Update: Okay, after a little research, I realized that you can never reference a type in the unnamed package from a named package. Makes sense, but definitely not what you are running into.
I can compile code under JDK 1.4.2_19 and utilize it just fine in a Java 6 Eclipse project. I think that this problem is something specific to your environment. In this situation, I would backup Eclipse and recreate everything (JDK installation, workspace, projects) from scratch, to see if I could clear it up.
I had another issue with some legacy code written in Java 1.4.x: the authors loved enumerations and loved to name the corresponding variables 'enum'. They even used it for package names. And this prevents from compiling the code under Java 1.5 (or higher) quite successfully.
Changing that automatically is quite an issue.
May be you have defined Eclipse to throw compiler errors on use of deprecated methods or classes?