Allan allan
Allan allan

Reputation: 9

Could not find or load main class HelloWorldApp

I got that error while running the program, below are few more details

I have created a folder on C drive with name as myapplication I have saved the code with file name as HelloWorldApp.java using notepad.

At the command prompt I have c:\myapplication> Then I am typing the following command java -cp . HelloWorldApp, below is how it looks

c:\myapplication>java -cp . HelloWorldApp
Error: Could not find or load main class HelloWorldApp

Kindly help me solve this, so that I can proceed further.

Upvotes: 0

Views: 287

Answers (5)

Bhaskor Jyoti Sarmah
Bhaskor Jyoti Sarmah

Reputation: 126

write

c:\myapplication>javac HelloWorldApp.java

Upvotes: 0

Milaci
Milaci

Reputation: 515

Compile first:

C:\myapplication> javac HelloWorldApp.java

Now run with C:\myapplication> java HelloWorldApp and you see the "Hello World" printed in command prompt.

Upvotes: 0

slavik
slavik

Reputation: 1303

You have to compile file

c:\myapplication>javac HelloWorldApp.java

then

c:\myapplication>java HelloWorldApp

Upvotes: 2

kirti
kirti

Reputation: 4609

You will have to save your program in the java bin folder otherwise you will get error...

And if you want to save the program anywhere and compile it then you will have to set up the path for that..

Try this
Run Command Prompt (found under All Programs/Accessories in the Start menu).  Type

C:\> cd \mywork

This makes C:\mywork the current directory.

C:\mywork> dir

This displays the directory contents.  You should see HelloWorld.java among the files.

C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin

This tells the system where to find JDK programs.

    C:\mywork> javac HelloWorldApp.java

    This runs javac.exe, the compiler.  You should see nothing but the next system prompt...

    C:\mywork> dir

    javac has created the HelloWorldApp.class file.  You should see HelloWorldApp.java and HelloWorldApp.class among the files.

    C:\mywork> java HelloWorldApp

for more info http://www.skylit.com/javamethods/faqs/javaindos.html

This runs the Java interpreter.  You should see the program output:

Hello, World!

Upvotes: 0

Albert Scholtz
Albert Scholtz

Reputation: 347

Please look at running the javac command first to compile your class. A class file should be generated which will work with your java command.

Upvotes: 0

Related Questions