I am having a runtime error ONLY when I test my Java program on a mac computer. It tests perfectly fine on various Windows operating systems. This is the error message I get on a Mac computer...
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/swing/GroupLayout$Group
at project.MainPanel.calculateButtonActionPerformed(MainPanel.java:198)
at project.MainPanel.access$200(MainPanel.java:32)
at project.MainPanel$3.actionPerformed(MainPanel.java:97)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1882)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2202)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:5602)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
at java.awt.Component.processEvent(Component.java:5367)
at java.awt.Container.processEvent(Container.java:2010)
at java.awt.Component.dispatchEventImpl(Component.java:4068)
at java.awt.Container.dispatchEventImpl(Container.java:2068)
at java.awt.Component.dispatchEvent(Component.java:3903)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
at java.awt.Container.dispatchEventImpl(Container.java:2054)
at java.awt.Window.dispatchEventImpl(Window.java:1801)
at java.awt.Component.dispatchEvent(Component.java:3903)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatch! Thread.j ava:269)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)\
I do not know why this is happening. Could the fact that I compiled the program on a Windows computer be the problem? That is the only thing that I could think of.
Under OS X the default version of Java is Java 1.5.
The only good Way to ensure the right jvm is with java Web start.
Without being able to test this, I would assume that this is because the Java version that you compiled this under is greater than the Java version that you are running on your Macintosh.
I suggest that you check the versions of each and make sure that the version which you are running under Mac OS is the same, or later.
Alternatively, you could try using the "-target" option for javac to set an older version and see if that helps.
You have to upgrade your java version to 1.6 minimum. First of all you check your java version on terminal by typing "java -version" if you don't have the 1.6, go to the Spotlight, write java and in Java Preferences drag and drop Java SE 6 to the top of the list, and it was done. Exit and that's it.
Related
I've been working with Java for a bit now and the JDK/JRE version has given me quite a bit of trouble lately. I am developing using the Intellij IDEA IDE and it of course uses the latest version of the JDK, 14. However when I attempt to execute software compiled with JDK 14 outside the IDE, I get an error that the JRE isn't new enough to run this software. So I updated Java on my computer and another machine and attempt to run again without any success. After some digging, I tweaked my machine to use the JRE included in the JDK 14 which is compatible.
However it is kind of odd that I had to do that, one would think that the latest version of java should of been enough to run applications made with the latest version of the JDK (14). Right now Java is version 8 build 251 and says there is no newer update available. If JDK 14 is out for a while now, why would they not update the version of Java they ship?
The problem is partially solved, as only the machine I am using for development is capable of executing the created applications. Other people I've sent them to have been unable to run them, despite having the latest version of java. Also it is a pain to get the latest JDK, especially when having limited experience on how to get rid of old versions, change path point to the latest version, get the right package (open/oracle JDK) and do that for windows and several distrubutions of linux. What is going on? Did I get Java from the wrong place and everyone else as well? Why are oracle doing this and why are there no java updates since clearly there exists a newer version?
Starting with Java-11, separate JRE does not exist anymore. In other words, if you are using Java-11 or above, you should care about JDK only.
You should uninstall JRE-8 from your machine and make sure your JDK-14 bin folder in the PATH variable. Some application even requires JAVA_HOME to work and therefore you should make sure that your system has an environment variable called JAVA_HOME and its value set to the root folder of JDK-14 (i.e. one level above your JDK bin).
Q: What should my clients do to run my application compiled on JDK-14?
Ans: Your clients must install JDK-14. Also, check this thread for some alternatives.
You're confusing how IntelliJ or JDK are used on the OS. IntelliJ, now, often comes with its JDK binaries (but even this can be configured, IntelliJ can be configured to use any JDK/JRE build you'll provide to it); however, if you run your Java application out of IntelliJ, most likely you're using Java installed locally on your OS, which might be referenced via your JAVA_HOME environment variable.
I'd suggest to:
Check java -version in your shell (and hence you'll see what JVM instance your OS spins up when you run a Java application);
Check where java (on Windows, or which - on Linux) in your shell, to see all the Java binaries available on your OS.
Try to uninstall Java SE Development Kit and Java JRE(if you have both in your machine) and reinstall both again, JDK and JRE both, I am sharing my google drive link where you can find the latest version of both JDK and JRE and when you are done installing, add there bin folder path in the Environment Variables of your machine.
usually when installing an updated JRE, the environment variables will be set so that running any java command in CMD will use the new version.
I've just installed JDK 11 which doesn't have a JRE equivalent - well it's in the JDK - but java commands are still being sent to JRE 8.
This is no problem for me, I can always change the environment vars myself and point to "C:\Program Files/java/jdk-11/bin/java.exe", but anyone who wants to use my program, which requires Java 11, will not have their variables set and it's a bit much to ask them to do so.
Why are they not being set on a standard Java 11 install? Am I being stupid?
Oracle is still pushing 8 as the "end user" Java install. That's why it's the only one you can find on java.com. Newer versions of Java are designed either for back-end use on servers, or to be bundled with the application itself. The latter option is what you want.
I have a C++ application that uses JNI to create a Java virtual machine. I have the latest version of Java installed - JDK 8-144. If I run "java -version" it comes up and tells me that Java Hotspot 8 is the JVM. I have JAVA_HOME defined in the .profile file, and it works -- JAVA_HOME points to the JDK8-144 folder.
My application is including jni.h from the latest JDK. Our code creates a JVM with the JNI_VERSION_1_8 version flag. On Windows, this compiles and works perfectly.
The problem is that when we compile this code on the Mac, and use the JVM Framework for linking, we end up with an executable that, when run, says that there's "No Java Runtime present" and a dialog comes up that says we need to install the Version 6 JVM. This happens if we run the application from either the Bash terminal or from XCode.
I've researched this and there are other people who have had this identical issue. Everyone seems to suggest that JAVA_HOME needs to be pointing to the correct place, and mine is. Again, java -version works correctly. The whole thing is quite puzzling.
Does anyone know the right way to solve this? I've tried two different Macs with identical results. They are both running the latest version of macOS Sierra.
Thanks!
Dan
I'd like to write a desktop app using Java and I'm wondering if I can get the app to execute on computers running both Window 7 and Windows 10. I've got Eclipse set up with JavaSE 1.8 and I'm running Windows 8.
Thanks!
Yes. Once it's compiled, you can pass your app on to any computer with a JVM (Java virtual machine, aka "any machine with java installed") and your application will be able to be run. There are versioning caveats, for instance an old version JVM won't be able to run newer code (compiled to a higher version) but you probably won't have to worry about it. If you need to, you can set your compiler to compile to earlier versions (and you can set this in eclipse) but you probably won't have to bother with it.
Here are some details about my system:
Windows 7 (64-Bit)
JDK 1.8.0_05 (64-Bit)
JDK 1.7.0_51 (32-Bit)
Eclipse - Luna 4.4.0 (64-Bit)
Although my eclipse uses the 64-bit version of Java, I want to compile a Java program using the 32-bit version through the terminal.
Any suggestions how I can do that?
If you find that the Windows or Linux or Mac or 32-bit or 64-bit compiler produces a different output, this is most likely a bug (unless the compiler runs out of memory) Note: Eclipse has it's own compilers and it might generate different .class files. Usually this doesn't matter however when it does it can lead to subtle inconsistencies. I would make sure you always use the Oracle or IBM compiler if you can to avoid these issues.
However, you can specify the bit-ness in the same way you specify the version by setting the PATH or using the whole path when you run it. If you use an IDE, this is what it does for you, and many, many other things.