Nihir
Nihir

Reputation: 374

cmd "Error: Could not find or load main class" error

I've read through the other questions and have tried googling the solutions, but I couldn't find the solution I was looking for.

This program compiles and runs on NetBeans, but only complies on CMD. I WANT to get it running with CMD.

cmd window

program.java file

I'm not very good with Java - just starting out and this is a uni project.

Upvotes: 0

Views: 1399

Answers (3)

Kanti
Kanti

Reputation: 1082

First of all return back to your program directory

cd..

Now simply give the command

java Program

Upvotes: 0

Elliott Frisch
Elliott Frisch

Reputation: 201429

The program is in a package chess. Move up a folder,

C:\Users\Nihir\Documents\chess> cd ..\
C:\Users\Nihir\Documents> java -cp . chess.Program

Upvotes: 2

user4668606
user4668606

Reputation:

You have to use fully qualified names to invoke a class from the commandline. which would be "chess.Program" instead of "Program"

Upvotes: 1

Related Questions