Jason
Jason

Reputation: 320

Netbeans deleting a built class?

I have a NetBeans project with quite a few classes in it.

I've been working on this project for the past 3 weeks, and just started having this issue today. When clicking the "Run Main Project" button in NetBeans, I see the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: stockscreener/Stock
Caused by: java.lang.ClassNotFoundException: stockscreener.Stock
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: stockscreener.Main.  Program will exit.
Java Result: 1

So I first thought that my Stock.java file was not building. However, NetBeans did not report any errors when performing a clean/build.

I decided to take a look at the "build/classes/stockscreener" directory. After performing a clean/build, I can find Stock.class in my classes/stockscreener directory, however, when I click "Run Main Project" in NetBeans, I immediately see the class disappear (get deleted) from my view of the folder.

I made a few changes since the last time that the project could be successfully run, however these were minor changes to the code, and not to the project configuration (i.e.: the NetBeans GUI).

Note that I can successfully run the JAR version of this project.

Any ideas as to the cause of this?

Upvotes: 3

Views: 5084

Answers (4)

Locutus
Locutus

Reputation: 500

Try making a trivial edit to the source file or using "touch" to update the modification time of the .java file. This worked for me.

Upvotes: 0

netsuvi
netsuvi

Reputation: 26

I had the same problem. Windwos 7 File Explorer was showing the file with a grey X. Solution was to connect to the corporate file server.

Upvotes: 0

Bhaskar
Bhaskar

Reputation: 137

Disable the "Compile on Save" option for the project. Then try to do "Clean and Build" and "Run" the project.

Upvotes: 2

Deepak
Deepak

Reputation: 6812

You might have to cleare tha cache and rebuild the project to solve this problem. I had similar problem and when i cleared the cache the problem was gone. You have to go to user/.netbeans/6.9(or other version)/var/cache -> delete all the files under it and then restart your netbeans. then rebuild !!

Upvotes: 2

Related Questions