java.lang.NoClassDefFoundError from every class every day
Asked Answered
B

11

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)
Bostow answered 8/6, 2011 at 20:40 Comment(2)
Did you try doing a clean build? It helps sometimes in Eclipse.Anlace
Yeah, I've tried it, unfortunately it's a no-go.Bostow
P
41

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

Parachute answered 3/7, 2011 at 3:6 Comment(4)
If you are on Mac OS, the folder is: /Users/yourUserId/Library/Caches/NetBeans/version/index Replace yourUserId and version of netbeans.Jargonize
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.Diatribe
For windows users for simple copy and pasting: %appdata%\..\local\NetBeans\CacheCundiff
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 ;)Sharronsharyl
A
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.

Approximal answered 11/2, 2012 at 15:29 Comment(4)
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!!Empery
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 tooSudd
Very helpful answer!Intelligibility
I use NetBeans 12.4, and it's help me, thank you. (Project -> properties -> compile)Dogberry
G
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?

Gratis answered 8/6, 2011 at 20:49 Comment(7)
CLASSPATH problem, eh. I'll give her a whirl.Bostow
How do I post my classpath settings?Bostow
I just meant like, where do I get it?Bostow
Where do I find my CLASSPATH settings?Bostow
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.Gratis
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.Gratis
How does one reset the classpath?Walliw
O
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/

Olmstead answered 3/7, 2011 at 6:37 Comment(1)
By deployed, do you mean that I'm running it from the dist folder in another location? This is during debugging mostly.Bostow
M
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.

Molloy answered 21/1, 2012 at 4:10 Comment(0)
I
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.

Irremediable answered 24/9, 2012 at 21:33 Comment(0)
I
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.

Inquire answered 23/1, 2014 at 7:38 Comment(0)
M
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 (?)

Mckinney answered 9/4, 2017 at 14:18 Comment(0)
W
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.

Weakness answered 8/6, 2011 at 21:32 Comment(2)
Restarting Netbeans isn't really a solution, it's more like a workaround.Bostow
A solution is a method which solves a problem. A workaround is a solution which leaves some less important problems unsolved.Kellerman
C
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.

Counterreply answered 23/1, 2015 at 16:58 Comment(0)
N
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.

Namangan answered 15/9, 2022 at 18:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.