简体   繁体   中英

Java execution error: Could not find or load main class Main

I have the following directory, let's call it program/ , housing the following items:

Circle.java 
Point.java 
Shape.java
Triangle.java
Main.java
Geometry/` 

All of the .java files are part of the same geometry package, so I use this command to compile them together:

javac -d Geometry/ Main.java Triangle.java Shape.java Point.java  

This puts a .class file for each of the above files into the directory program/Geometry/geometry . It also puts those same files into the /program directory, so I guess my first question is why does it put those .class files in both locations? There doesn't seem to be a point in putting them with the .java files if they are contained by themselves in the geometry package directory.

Regardless of the answer to that, my main problem is that I can't seem to get my program to run. Inside Main.java , there is the Main class with a main() function that is supposed to work its magic. I have run the following command in both the program/ and program/Geometry/geometry with the same error, both listed below:

java Main 
Error: Could not find or load main class Main

Can someone explain what I am doing wrong here, and give me an answer to my first question as well? Thank you for any help you can provide!

Specify a classpath. In the same folder that you ran your compilation above, something like

java -cp Geometry Main 

Your Main.java file must have main() method.

Something like this:

public static void main(String[] args) {
    ...
}

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