Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 514
Jason Avatar asked Jan 27 '26 06:01

Jason


2 Answers

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 !!

like image 197
Deepak Avatar answered Jan 29 '26 18:01

Deepak


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

like image 41
Bhaskar Avatar answered Jan 29 '26 20:01

Bhaskar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!