1. Problem orientation
This type of error occurs when compiling (javac) and executing (Java) Java programs: the main class cannot be found or loaded:
First of all, the problem caused by improper configuration of environment variables is excluded. As long as the command line interface can recognize javac / Java commands, there is no problem with the configuration of environment variables. This problem often occurs because there is a package name in the Java source file, 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
C:\code>javac Hello.java
C:\code>java Hello
Error: Main class not found or could not be loaded Hello
2. Solutions
Delete the package name from the source file (not recommended); create a file path structure with the same package name under code (C:: – Code ⁃ com ⁃ example)\ Hello.java )
Compilation:C:\code>javac com/example/Hello.java
Run:C:\code>java com.example.Hello
Read More:
- Java Running Error: Could not find or load main class
- [Solved] Maven Project Packaging Error: Unable to find main class
- Java uses class array to report error Exception in thread “main” java.lang.NullPointerException solution
- Java will convert Excel to list set or JSON, export excel file to local, excel import and export, easyexcel tool class
- Problems and causes of Java’s main function format (public static void main (string args()))
- [Javac compilation exception] javac compilation prompts that the package in jdk cannot be found error: package jdk.internal.org.objectweb.asm does not exist and error: cannot find symbol
- [Solved] Java XXX: unable to find topic engine in module path
- [Solved] Docker Elasticsearch8.4.0 Error: Exception in thread “main” java.nio.file.FileSystemException
- Nacos boot error, unable to find Java_HOME [How to Solve]
- How to Solve Java Runtime (class file version 53.0)ERROR
- Java Error: No enclosing instance of type Main is accessible. Must qualify the allocation with an encl
- [Solved] Hongmeng compiles error: Unable to find the java component with apiVersion 4.
- [Solved] Initialization of anonymous inner class member variable causes java.lang.stackoverflowerror
- java: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x590
- [Solved] tomcat Startup Error: java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
- Gephi cannot find Java 1.8 or higher [How to Solve]
- Java: How to Find the Minimum Value from a Random Array by Bubble Sort Method
- [Solved] Failed to load class org.slf4j.impl.StaticLoggerBinder
- [Solved] qrcode-error: Exception in thread “main” java.lang.NoClassDefFoundError…
- [Solved] spring source code compile error: target package does not exist