• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error: Could not load main class

 
Omar Perez
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

The problem:
When I try to run the a java.class file from the command prompt, but it just wont do it.

The code:
A Simple Hello World



JDK: jdk1.7.0_05

System Variables:

JAVA_HOME : C:\Program Files\Java\jdk1.7.0_05
CLASS_PATH : C:\Program Files\Java\jre7\lib
Path: %JAVA_HOME%\bin

Using the 64 bit version of JDK
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you type to run the file?
 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Omar Perez wrote:Greetings,

When I try to run the a java.class file from the command prompt



You are getting the error while running or while compiling, and what is the error that you are getting?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing wrong with your code. Here is what I got:

C:\slop>cat HelloWorld.java
public class HelloWorld {
public static void main(String[] args){

System.out.println("Hello World");


}
}

C:\slop>javac HelloWorld.java

C:\slop>java HelloWorld
Hello World

C:\slop>

I am wondering if you are typing "java HelloWorld.class" - which is wrong. It should just be "java HelloWorld", but unless you tell us, we can't really help.
 
Omar Perez
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:There is nothing wrong with your code. Here is what I got:

C:\slop>cat HelloWorld.java
public class HelloWorld {
public static void main(String[] args){

System.out.println("Hello World");


}
}

C:\slop>javac HelloWorld.java

C:\slop>java HelloWorld
Hello World

C:\slop>

I am wondering if you are typing "java HelloWorld.class" - which is wrong. It should just be "java HelloWorld", but unless you tell us, we can't really help.


That was it, I was typing a full qualified name (java.class), thank you very much.

It will help me a lot, now that I want to do it without using IDEs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic