I need help "error: file not found: C:\Program Files\Java\jdk-18\JCreatorV4\MyProjects\main.java
Usage: javac <options> <source files>" this and this-"Error: Could not find or load main class main
Caused by: java.lang.ClassNotFoundException: main"
keep popping up

the code I'm using is the simple hello world for java

the name is main.java

public class main
{
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

I'm sorry this smight be a dumb question but I'm a newbie and I got no help from reddit so Im hoping to get help here

Recommended Answers

All 5 Replies

If I were to bet there is no file called main.java
Many try to use the old Notepad and save the file as main.java but Notepad's saved file is actually "main.java.txt" which causes the file not found error.

  1. In Windows File Explorer be sure to display file extensions.
  2. Get a better editor or IDE.
commented: this gets fixed when I uninstall/install the software again. but this prob always pops up after like 1 day +0

It looks like you are using a directory inside c:\Program Files\ for your own files. That's never a good idea.
Create a directory in your home for such use. Make sure that's the working dir in your command prompt. Make sure the JDK dir with javac.exe etc is in your PATH.

@James points out the other issue.

@OP, time to setup up your own projects folder. Also, get a decent IDE that won't rename your files to .txt

PS. Via EMAIL I find you may be using https://en.wikipedia.org/wiki/JCreator but you didn't leave your comment with that detail. Time to put your files in your own home/user folders.

JCreator ? Never heard of it. wikipedia shows its last release as being in 2015, and the web site that links to is no longer there. It doesn't even use the standard JAVA runtime. Unless someone knows better it looks like a real dead-end. Best avoided.
If you want a Java IDE the "big 3" are Eclipse, IntelliJ IDEA, and NetBeans. In my opinion Eclipse and NetBeans are best suited to professional developers - feature-packed but a huge learning curve. IntelliJ IDEA is the one I would suggest for a beginner, but BlueJ is also popular.
But remember you don't need an IDE at all for simple programs, and you may get a better grasp of the basics by using a simple text editor and Java.exe

commented: I find instructors to make up the lesson plan and then never update it for a decade or more. +16

Sounds like a poor project setup, and not having your classes as part of packages makes that even worse.
Not using a normal naming convention for classes makes things worse still.
Not knowing your tools doesn't help either.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.