Error "Could not find or load main class" in Java: causes and solution
Hello everyone! I'm a beginner in Java and have been struggling with a problem for the second week. I'm writing a simple "Hello, World!" program, but when trying to run it from the command line, I get the error:\n\n```\nError: Could not find or load main class HelloWorld\n```\n\nHere's my code (file HelloWorld.java):\n\n```java\npublic class HelloWorld {\n public static void main(String[] args) {\n System.out.println("Hello, World!");\n }\n}\n```\n\nI compile the file with the command `javac HelloWorld.java` — it succeeds, and a `HelloWorld.class` file is created. But when I enter `java HelloWorld`, this error appears. I am in the same folder where both files are located. I tried specifying the full path — it doesn't help.\n\nI have Windows 10, JDK 17 installed, and the JAVA_HOME variable is set. I read on the internet that the problem might be...
No answers yet.
Log in to leave an answer