Im using Java SDK 1.7 for Windows 7 via cmd.exe. Until a few hours ago everything worked correctly, all of a sudden I was not able to run my compiled class files, consistently presented with an error in the header.
It seems I can compile my My.java file, but I cannot run the resulting class file (My.class). I constantly get the error "Error: Could not find or load the main class My.class". I tried this with several other class files, all this leads to the same problem.
The environment variable "Path" is set to "C: \ Program Files (x86) \ Java \ jdk1.7.0_05 \ bin" if you are interested
I tried reinstalling, creating and setting the classpath variable (no luck) and even using directly
java -cp . My.class
teams.
I tried these posts all to no avail, so why am I posting:
Error: could not find or load the main class
Error: could not find or load the main class - newbie
Could not find or load main class
Java 1.7.0_03 Error: could not find or load the main class
If that matters, my code is:
import javax.swing.JOptionPane; class My { public static void main(String[] args) { final double x = 3.2; int i = (int)x; double m = 0; if (x < 4) { String saySomething = JOptionPane.showInputDialog(i); System.out.println(saySomething); } else { String saySomething = JOptionPane.showInputDialog(i); System.out.println("Hello World"); } while (m < 10) { System.out.print(" While Loop "); m++; }; for (i=1; i < 10; i++) { System.out.println("For Loop"); }; } }
source share