aspose file tools*
The moose likes Beginning Java and the fly likes Error: Could not load main class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error: Could not load main class" Watch "Error: Could not load main class" New topic
Author

Error: Could not load main class

Omar Perez
Ranch Hand

Joined: Jul 08, 2011
Posts: 36
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

Joined: Aug 05, 2007
Posts: 136
    
    1
What do you type to run the file?
Vishal Shaw
Ranch Hand

Joined: Aug 09, 2012
Posts: 179
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?


Programming is about thinking, NOT coding
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11405
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Omar Perez
Ranch Hand

Joined: Jul 08, 2011
Posts: 36
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error: Could not load main class