-1

So I was making a java program in Netbeans IDE 8.2 and when I tried to run it, I got this error:

Error: Could not find or load main class helloworld.HelloWorld
C:\Users\name\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)

(Assume that helloworld is my project name and HelloWorld is my class name)

Everything was fine before, and I can't think of what I did that would cause this error to happen. This is the first time this error has happened to me so I don't know what to do. The code doesn't seem to have any errors.

Other projects of mine seemed to also have the exact same problem even though I haven't opened or edited them in weeks prior to this error occurring.

I tried many other ways but none of them seems to do the trick. Including deleting the cache folder and setting the main class through the properties tab.

Here's a screenshot of my code with the error, my name is crossed out: enter image description here Even if I type my code directly in the main class, which is class6homework.java, the error still occurs but it says class6homework.class6homework instead of the one in the screenshot.

Any ideas on how I could fix this?

UPDATE: I got it to work by moving the folder that contains the project to my desktop, didn't know why it wouldn't work in my original location. Thanks for the help.

2 Answers2

1

Perhaps you don't have the main method included. If that is not the problem, try right clicking your class in the project tree and look for an option that says "Set as main class" or something like that

gabopushups
  • 185
  • 2
  • 11
0

Possible Fixes:

Fix 1

  1. Go to project properties (right click on the folder of your project in netbeans)
  2. On left tab where it shows the categories, click on the "Run" selection
  3. Then click on Browse to find the Main class you use on your project

Fix 2

  1. Go to C:\Users\name\AppData\Local\Netbeans
  2. delete the Cache folder.
  3. Rebuild and Run

Fix 3 Download most recent version of Netbeans

Fix 4 Download most recent version of JDK and configure Netbeans to use that

Alexandros Kourtis
  • 539
  • 2
  • 6
  • 20