Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find or load main class

Tags:

java

windows

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:

"Could not find or load main class"

I am storing all my programs in javalab folder. I have set the path to it. Procedure looks like this:

C:\Users\user>cd\

C:\>cd javalab

C:\javalab>autoexec.bat

C:\javalab>set path=C:\Program Files\Java\jdk1.7.0\bin

C:\javalab>javac p1.java

C:\javalab>java p1
Error: Could not find or load main class p1

C:\javalab> 
like image 587
Lakshmi devi C Avatar asked Oct 04 '11 11:10

Lakshmi devi C


Video Answer


3 Answers

I was having a similar issue with my very first java program.

I was issuing this command

java HelloWorld.class

Which resulted in the same error.

Turns out you need to exclude the .class

java HelloWorld
like image 144
Chris Dev Avatar answered Oct 21 '22 10:10

Chris Dev


Try:

java -cp . p1

This worked for me when I had the same problem, using Fedora (linux)

like image 12
leat Avatar answered Oct 21 '22 11:10

leat


Simple way to compile and execute java file.(HelloWorld.java doesn't includes any package)

set path="C:\Program Files (x86)\Java\jdk1.7.0_45\bin"
javac "HelloWorld.java"
java -cp . HelloWorld
pause
like image 9
Prasaathviki Avatar answered Oct 21 '22 10:10

Prasaathviki