Error:
/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java
-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=53049:
/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 Scratch
Error: Could not find or load main class HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
Process finished with exit code 1
Class File:
public class HelloWorld {
public static void main(String... args) {
System.out.println("Hello");
}
}
As you can see the above class does not have any complication issues or syntax errors. There can be multiple reasons that you may get the error, below are some of the solutions that may work for you!
- Make sure that the class name is correct.
- Go to Menu: Build -> Re-Build Project.
- Remove .idea directory from your project and restart IDE.
- Go to Files: Invalidate Cache/ Restart...
- Check your project has a out folder, if not create one, example: /Users/code2care/IdeaProjects/java-examples/out
- Edit Build/Run Configurations and check if you have selected the correct Java class that has a main method.

Fixing Could not find or load main class error
More Posts related to Java,
- Drop table using Java JDBC Template
- Java - Check if array contains the value
- YAML Parser using Java Jackson Library Example
- Java Jackson ObjectMapper Class with Examples
- Get Client IP address from HTTP Response in Java
- How to Word-Warp Console logs in IntelliJ
- Exception in thread main java.lang.NoClassDefFoundError: package javaClass
- Setting Java_Home Environment variable on Windows Operating System
- Fix: Maven - Failed to execute goal - Compilation failure - Source/Target option 5 is no longer supported. Use 7 or later
- Java SE JDBC Select Statement Example
- How to extract Java Jar/War/Ear files in Linux
- java: unclosed string literal [Error]
- [Solution] Exception in thread main java.util.EmptyStackException
- Read YAML file Java Jackson Library
- What Java version is used for Minecraft 1.18
- [Java] How to throws Exception using Functional Interface and Lambda code
- [Program] How to read three different values using Scanner in Java
- Java 8 Predicate Functional Interface Examples
- Display Era details (AD BC) in Java Date using SimpleDateFormat
- Convert String Date to Date Object in Java
- Struts 2 Hello World Example in Eclipse
- Read a file using Java 8 Stream
- Java - How to set custom thread name?
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- java: ']' expected error [fixed]
More Posts:
- [Ubuntu] Search a package and versions using apt command - Linux
- List of Code Snippets/Templates to Eclipse IDE - Eclipse
- Unsupported major.minor version 52.0 in java - Java
- macOS Ventura: In order to use Xcode.app you need to update to the latest version - MacOS
- [IRCTC] Indian railways official eRail API 1.1 for developers to get train info - HowTos
- Java equals method - Tutorial - Java
- How to turn off AirPods Nearyby notifications on macOS Big Sur? - Apple
- Calculate Sum of List elements using Java Streams - Java