简体   繁体   中英

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.

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.

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

Run following command:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM