23

I have tried reinstalling netbeans, I have tried reinstalling java. I'm not sure what's going on but I get this exception at random from every class until I restart netbeans. Anyone with similar problems?

run:

Exception in thread "main" java.lang.NoClassDefFoundError: com/company/utilities/formatters/DateFinder
    at com.protocase.db.DatabaseAdapter.<init>(DatabaseAdapter.java:44)
    at packagingqueries.PackagingQueries.getBatchIDsForOperation(PackagingQueries.java:42)
    at packagingqueries.PackagingQueries.main(PackagingQueries.java:20)
Caused by: java.lang.ClassNotFoundException: com.protocase.utilities.formatters.DateFinder
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
2
  • Did you try doing a clean build? It helps sometimes in Eclipse.
    – Reddy
    Jul 1, 2011 at 19:21
  • 3
    Yeah, I've tried it, unfortunately it's a no-go. Jul 5, 2011 at 14:06

11 Answers 11

41
+50

Sometimes, the NetBeans local cache directory becomes corrupted (either because the application crashed earlier or because something else/undefined happened). NetBeans starts to behave strangely. Re-installing does not help, because the local cache directory is not always deleted.

If you are 100% sure your application does not have a path problem:

  1. Close NetBeans
  2. If you are on Windows go to c:\Users\youruserid\.netbeans\7.0 (else find the corresponding directory on your system)
  3. Delete the content completely
  4. Restart NetBeans

NetBeans will recreate the content of this directory. This may solve your issue. If it does not, then your issue is in the configuration of your application or in a corrupted library for sure.

If the location where these files are stored runs out of space for writing, this problem can arise. As usual, one needs to make space...

4
  • 1
    If you are on Mac OS, the folder is: /Users/yourUserId/Library/Caches/NetBeans/version/index Replace yourUserId and version of netbeans.
    – Enkk
    Feb 27, 2015 at 15:17
  • 12
    For NetBeans 8.0 on Windows 8, the path is C:\Users\[User Name]\AppData\Local\NetBeans\Cache\8.0 This solved my problem which persisted after project rename, reset, reconfig, and recreate.
    – Sheepy
    Jun 9, 2015 at 10:31
  • 1
    For windows users for simple copy and pasting: %appdata%\..\local\NetBeans\Cache
    – sibbl
    Aug 11, 2016 at 10:03
  • Thank you! This works perfectly! It can be quite frustrating when things randomly stop working and it seems that cache is usually the cause of the problem ;)
    – JFreeman
    Mar 19, 2019 at 2:42
31

You might be running your project with "Compile on Save" Option. Please uncheck this option.

I know this option is very helpful but "Compile on Save" causes such problems.

4
  • 2
    You Sir... are a life saver!! Was working on a relatively extensive project (circa 80 plus code files.) and all of a sudden Netbeans started complaining that it was unable to locate a core subsystem class!!! Tried completely reloading the project and its dependencies, multiple restarts and was just about to re-install Netbeans when I saw your post; turns out simply disabling "Compile on Save" fixed the problem. Many thanks!! Apr 10, 2015 at 12:22
  • This worked for me too on 8.1 (Mac OSX). Cleaning the cache didn't help. I wonder if this relates to netbeans.org/bugzilla/show_bug.cgi?id=194263 too
    – Bram
    May 19, 2016 at 9:14
  • Very helpful answer!
    – Nathan G
    Oct 20, 2020 at 11:58
  • I use NetBeans 12.4, and it's help me, thank you. (Project -> properties -> compile)
    – Kipoti
    Feb 5 at 9:56
5

This is normally a CLASSPATH problem. Try resetting the CLASSPATH, and/or make sure all third party JAR's are actually present in the correct locations. In some rare cases you will get this problem when the JVM has problems loading a third party jar due to version incompatibilities. Can you post your CLASSPATH settings?

7
  • CLASSPATH problem, eh. I'll give her a whirl. Jun 9, 2011 at 14:49
  • How do I post my classpath settings? Jun 9, 2011 at 14:50
  • I just meant like, where do I get it? Jun 9, 2011 at 20:46
  • 1
    Not sure if you got this figured out yet or not. But to get your classpath settings open up the project properties and go to Libraries. Copy and paste here the settings for Run & Run Tests.
    – Perception
    Jun 16, 2011 at 22:10
  • 1
    Not sure if Netbeans 7.0 has updated the properties panel but it sounds like it has. I will check after work and update my comment above.
    – Perception
    Jun 20, 2011 at 18:46
3

@dah: what I understand is that your code is deployed in netbeans configured JDK as a simple java application. When you run your application, you ran into NoClassDefFoundError issue? Is it correct understanding. NoClassDefFoundError can be due to any of following issues:- i) class is really not present. sol: Obvious solution. ii) Class is present but still error. Sol: check if it present in classpath. classloader visibilty is important here. iii) Class is present and present in classpath but still error. Sol: If you have class in a jar it might be due fact that jar had produced using different version of java than what are you using. So you need to recompile jar and then replace new jar. check this:- http://code.google.com/p/versioncheck/

1
  • By deployed, do you mean that I'm running it from the dist folder in another location? This is during debugging mostly. Jul 5, 2011 at 13:42
3

I've had the same problem Class not Found error and after reading some of these comments found that netbeans will lose reference to added jar files in the library. Deleting the jars and adding them again to the library will recreate the reference.

3

I had a similar issue that was producing the NoClassDefFoundError caused by ClassNotFoundException.

In my case I had copied a dependency into my pom.xml that included the line

<scope>provided</scope>

It seems that netbeans/maven loaded the jar into Netbeans for development and compilation, but left it out of the executable jar since I said it was "provided".

When I removed this line from my pom.xml the error went away.

2

A very Simple Way is that Modify your Code some Bit means some little Changes and Clean and Do again Build. means any How make Your Compiler Force to Compile your Program form Again and that way it will be run.

Try that will be helpful.

2

For me, this problem occurred right after NetBeans said "low memory". I tried the other solutions, restarting, rebooting, removing various dirs as above, to no avail.

For whatever reason, it worked to delete the Classes dir from /build and then do a Clean/Build. Don't know why that worked, because I thought that dir got deleted during the "Clean" anyway... perhaps deleting it confused NetBeans in a constructive way (?)

1

I'm running Netbeans 6.9.1 and every once in a while it just gets confused and starts saying it can't find some references. I run it on two different windows machines with different configurations and it occurs on both of them. Most of the time it involves a .jar file. The only solution I have been able to come up with is to restart Netbeans.

2
  • Restarting Netbeans isn't really a solution, it's more like a workaround. Jun 20, 2011 at 16:08
  • A solution is a method which solves a problem. A workaround is a solution which leaves some less important problems unsolved. Nov 1, 2016 at 12:06
0

I used the solution posted by JVerstry. I worked for me on:

ubuntu studio with netbeans 8.0.2

the problem appeared after installing the jax-rpc plugin to create a web service client.

hope this will help anyone else.

0

Such error can happen even in netbeans 15, so it looks like it is version independent. It can be related to same of those situations mentioned in all those valuable posts above. It can be related to "compile on save" especially when using real time compile of classes with javax.tools. Sometimes completely deleting netbeans cache solves the problem, but sometimes, after deleting cache I had to clean and compile the project before running it.

So to sum up, a possible way can be:

  1. Delete netbeans cache and try on/off "compile on save" setting
  2. Clean & compile then run the project

...next time that it will suddenly happen, repeat those steps. It can also appear as a "classloader" error or "cannot find main class" error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.