Java prompt error: main class cannot be found or cannot be loaded

Posted May 27, 20201 min read

C:\ Java \ IdeaProjects \ java> java xxxx
Error:Cannot find or load main class xxxx

Check if java is available in Idea terminal. If it is not available, edit the compiler output path:file → project structure → module → path → output directory or settings → tools → terminal → project settings → environment variables

//https://cn.fankuiba.com
C:\ Java \ IdeaProjects \ java> java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment(build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM(build 25.231-b11, mixed mode)

Check whether java is available in the command line PowerShell, if not available, configure the system environment variables

PS C:\ Users \ XX> java
...
For more information, see http://www.oracle.com/technetwork/java/javase/documentation/index.html.
PS C:\ Users \ XX> java xxxx
Error:Cannot find or load main class xxxx

Manually copy the class file under the project path to C:UsersXX> can be executed normally
You can "temporarily" solve this problem by storing the path from the CD to the class file in each terminal