Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Hello, world!" - Could not find or load main class

Tags:

java

Computer OS: Windows 7 Language: Java

After long time back I am using java, I am getting problem while running the hello world program:

public class Hello 
{
    public static void main (String args[]) 
    {
         System.out.println ("Hello World!");
    }
}

I saved this code in Hello.java File, and then compiled using cmd:

C:\Users\XYZ\Desktop>javac -version
javac 1.6.0

C:\Users\XYZ\Desktop>javac Hello.java

C:\Users\XYZ\Desktop>java Hello
Error: Could not find or load main class Hello

C:\Users\XYZ\Desktop>  

Can you explain why the error message above was thrown?

like image 349
yogeshkmrsoni Avatar asked Apr 25 '14 06:04

yogeshkmrsoni


People also ask

Can you call a class main in Java?

The main() method must be called from a static method only inside the same class.


1 Answers

You are missing one "}" at the end of the program

public class Hello 
{
    public static void main (String args[]) 
    {
       System.out.println ("Hello World!");
    }
}

and then try

java -cp . Hello
like image 114
Neel Avatar answered Sep 30 '22 17:09

Neel