Bob Whitman
Bob Whitman

Reputation: 17

Java could not find or load main class error

For some reason, I can't get java to run my program. Whenever I try I get the message

"Error: Could not find or load main class Project"

In Command Prompt I type cd Documents since the file is in my Documents folder, type

javac Project.java

then

java Project

to try and run it but I get the above error message.

import java.util.Scanner;

import java.text.DecimalFormat; 

public class Project
{
    public static void main(String[] args)
    {
        Code and stuff
    }
}

There's a fair bit of code that I left out but I think this is the part that's messed up. Let me know if you need to see the rest of the code and I'll edit this.

Upvotes: 0

Views: 1109

Answers (2)

Rahman
Rahman

Reputation: 3785

You have add the path of .class files in classpath during execution

Run following command:

java -classpath C:\Users\DELL\Documents Project

Upvotes: 0

Elliott Frisch
Elliott Frisch

Reputation: 201399

Change

java Project

to (assuming Project.class is in your current folder)

java -cp . Project

as it is, you aren't setting a class-path.

Upvotes: 4

Related Questions