Home> Java> JavaBase> body text

Java error: Reasons and solutions for main class not found or unable to be loaded

Release: 2019-11-28 09:45:01
Original
63791 people have browsed it

Java error: Reasons and solutions for main class not found or unable to be loaded

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"); } }
Copy after login

It seems that there is no problem, Execution:

C:\code>javac Hello.java C:\code>java Hello 错误: 找不到或无法加载主类 Hello
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!