Okay since .class files use the JRE to run, this theoretically makes them platform-independent. Since, the class file contains the byte-code to that the JRE uses to run it, it should run whether that JRE resides on a Windows machine, a Linux box, or on a Mac. I wrote a Java program and the class file executes perfectly on my Windows laptop, but will not work on my Mac. When I try to run it in OS X I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: CalMortCalc$Interact at CalMortCalc.<init>(CalMortCalc.java:384) at CalMortCalc.main(CalMortCalc.java:522) Caused by: java.lang.ClassNotFoundException: CalMortCalc$Interact at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 2 more
no dude the .class file is common to all the platforms there might be any warning in your code please note it.
Where is CalMortCalc$Interact.class located when you run it on OSX? Do you need to adjust/declare a CLASSPATH variable?
I figured it out. I had forgotten that I had created and implemented a class called interact within the program. At compile time java automatically creates that class file (CalMortCalc$Interact). Both of those files must be present for the program to execute, but I only copied the CalMortCalc.class, not both. I brought over CalMortCalc$Interact.class and the program works fine. Sometimes it is the simplest things that leave you puzzled. Turns out all I really needed was a little sleep. lol
Join our real-time social learning platform and learn together with your friends!