JAVA encountered errors (error) and solution records

1. Error: Cannot find or load the main class

Run java+class name in the cmd command window.
First of all, you should ensure that the environment variables are configured. Use the java -version and javac -version commands. If no error is reported, it should be ok;
second, you should cd to the corresponding folder;
there are errors. The possible reasons are as follows:
Reason 1 : More added class suffix. . Such as

java helloworld.class

Direct java helloworld is fine;
reason two : The
helloworld code is as follows:

package project1;

public class helloworld {
    
    
	public static void main(String[] args) {
    
    
	System.out.println("helloworld!");
	}
}

When programming with software such as eplise, there is a package xxx, which should be cd to the xxx directory, and then run:

java project1.helloworld

This generally works normally.

Guess you like

Origin blog.csdn.net/weixin_45371989/article/details/108428217