Command Prompt cannot find class in my Java program

Closed
zlloyd1 Posts 10 Registration date Tuesday December 11, 2012 Status Member Last seen February 4, 2013 - Dec 11, 2012 at 12:38 AM
shoaibista Posts 8 Registration date Friday May 24, 2013 Status Member Last seen May 27, 2013 - May 24, 2013 at 11:10 AM
Hello,
I have a simple graphical interface program that includes a message that reads "Hello World" in it. I know, not too original, but I am just getting started here with Java.
Anyway, this program compiles and runs flawlessly in NetBeans 7.2.1 IDE, and performs as expected. Unfortunately, I need it to run anywhere, and that means it must compile and run in the command prompt, but it won't because it complains it cannot find the main class in the file. Here is the code:
/ * HELLO WORLD Interface*/ 
package guihelloworld; 
/*Zachariah A Lloyd 
 * Hello World Graphical User Interface.... */ 
import javax.swing.JOptionPane; 
public class GUIHelloWorld { 
    public static void main(String[] args){ 
        JOptionPane.showMessageDialog(null, "HELLO WORLD");}} 

and as I said, this works perfectly in NetBeans, but is giving me grief when I try to run it from the command prompt. The exact error message I am getting is:
"Error: Could not find or load main class GUIHelloWorld.java"
but it compiles just fine in the command prompt....

Can anyone PLEASE tell me why I am getting that error??
THANKS IN ADVANCE!!

Related:

2 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Dec 12, 2012 at 06:43 PM
you class is not in the path. Java is unable to find the class
most common way would be that you change dir to the location of the file and then execute the program
The file is on my desktop, and the directory is pointing to C:>Users>myname>Desktop, and it is still claiming to not be able to find the main class,. As shown in my code that I posted previously, there is a main class included in my program:
public static void main(String[] args){
JOptionPane.showMessageDialog(null, "HELLO WORLD");}}

So, I cannot for the life of me figure out what is the problem resulting in this error....
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Dec 13, 2012 at 12:37 PM
It cannot be on desktop because you have this line
package guihelloworld;
So the class must reside in folder "guihelloworld"

Other issue with your code is
/ * HELLO WORLD Interface*/
there cannot be space between / and * for it to be a comment

try this. I have removed your package statement. So now if you cd to the location of the compiled class and run the
javac GUIHelloWorld
it would word

/**Zachariah A Lloyd 
 * Hello World Graphical User Interface.... */ 
import javax.swing.JOptionPane; 
public class GUIHelloWorld { 
    public static void main(String[] args){ 
        JOptionPane.showMessageDialog(null, "HELLO WORLD");}} 
0
shoaibista Posts 8 Registration date Friday May 24, 2013 Status Member Last seen May 27, 2013
May 24, 2013 at 11:10 AM
->javac guihelloworld.GUIHelloWorld


try this