I have Windows 7, installed jdk1.7.0 and its supporting jre7.
My problem is compilation part works perfectly, but while running the Java program I get this error saying:
Here is my working env path variables after much troubleshooting
CLASSPATH
.;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip;C:\Program Files (x86)\Java\jdk1.6.0_27\bin
PATH <---sometimes this PATH fills up with too many paths and you can't add a path(which was my case!)
bunchofpaths;C:\Program Files (x86)\Java\jdk1.6.0_27\bin
Additionally, when you try to use the cmd to execute the file...make sure your in the local directory as the file your trying to execute (which you did.)
Just a little checklist for people that have this problem still.
I faced a similar problem in Eclipse. Whenever I clicked on the Run button it gave me the message, "Error: Could not find or load main class". But when I right click on the java file in the project explorer and Run As Java configuration, it works perfectly.
I think this is because it tries by default to run it in some other configuration which causes problems.
Hope this answer helps some.
i had
':'
in my project name e.g 'HKUSTx:part-2' renaming it 'HKUSTx-part-2' worked for me
First, put your file *.class
(e.g Hello.class
) into 1 folder (e.g C:\java
). Then you try command and type cd /d C:\java
. Now you can type "java Hello" !
Try:
java -cp . p1
This worked for me when I had the same problem, using Fedora (linux)
I had almost the same problem, but with the following variation:
That's quite odd behavour, I cannot completely understand it. Hope It'll help somebody. too.