5

Whenever I load NetBeans 6.9 (similar errors happened on previous versions also) then I let NetBeans finish scanning my projects and once it's done I try to run a profile which points to a class with a main method, NetBeans always says the main class is not found, even though it shows up in the list of classes once the error pops up.

If I select the class from the list and hit OK, the same error happens again (main class not found).

If I compile the main class, I still get the same problem.

I think I still get the same issue if I rebuild the entire project. -> when I compile the main project it compiles all projects, even those that are closed. What is going on?

The only way I have found so far to work around this is to close the project and re-open it and wait for the project scan to finish again.

This is incredibly annoying. Is there a fix for this?

Another strange thing I noticed is that my project seems to be building into the wrong JAR file name (though if I do the above step of closing and reopening the project it still works). I have two projects with different names, and even after having closed the other project and restarted NetBeans a lot of times, when I build the first project it uses the JAR file name for the second project that has been closed for a long time.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Coder
  • 1,375
  • 2
  • 20
  • 45
  • Ok i just verified rebuilding doesn't work either. Does anybody have an answer to this issue? It's really annoying. Thanks. – Coder Aug 21 '10 at 13:42
  • You can check my answer to this question here: http://stackoverflow.com/questions/1951375/netbeans-class-does-not-have-a-main-method/5665778#5665778 – Lucia Jun 18 '12 at 13:59

3 Answers3

12

I fixed a very similar behaviour by deleting NetBeans's cache. Delete the folder User\.netbeans\6.9\var\cache\index\.

Windows 7 and Netbeans 7.2: User\AppData\Local\NetBeans\Cache\7.2\index

Adrian
  • 3
  • 3
Radu Simionescu
  • 4,518
  • 1
  • 35
  • 34
  • 1
    Thank you so much for this answer! I was searching everywhere for how to fix this problem. – Elijah Jul 21 '11 at 16:53
1

For windows 8

Delete this directory C:\Users\Shubham\AppData\Local\NetBeans\Cache

Before doing so close netbeans.

Start Netbeans again and let it read the project.

Test project. Run project. It should work fine.

Shubham Das
  • 1,257
  • 11
  • 10
1

I didn't read the complete question, but try: Right click project > properties > run > browse for main class

Else try making a new project and then copy the scr folder from the old one to the new project.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Berty
  • 1,081
  • 1
  • 18
  • 49