1. Problem location
When compiling (javac) and executing (java) java program, this type of error occurs: cannot be found or cannot load the main class: (Recommended:java video tutorial)
1. First, rule out whether the problem is caused by improper configuration of environment variables. Just make sure that the command line interface can recognize javac/ java command, it means that there is no problem with the environment variable configuration.
2. This problem often occurs because the java source file contains a package name, such as the file C:\code\Hello.java:
package com.example; public class Hello{ public static void main(String[]args){ System.out.println("Hello"); } }
It seems that there is no problem, Execution:
C:\code>javac Hello.java C:\code>java Hello 错误: 找不到或无法加载主类 Hello
2. Solution
Delete the package name from the source file (not recommended);
Create it under code with the same name as the package The file path structure (C:\code\com\example\Hello.java)
编译:C:\code>javac com/example/Hello.java 运行:C:\code>java com.example.Hello
For more java knowledge, please pay attention to thejava Basic Tutorialcolumn.
The above is the detailed content of Java error: Reasons and solutions for main class not found or unable to be loaded. For more information, please follow other related articles on the PHP Chinese website!