2

I have a recurring bug when attempting to run Netbeans (7.2), last time I had it, I found somewhere that you can just move all your files to a new project. That will probably work, but the size of my project makes that quite a hassle. Here is the trace...

Exception in thread "main" java.lang.NoClassDefFoundError:  X.X.X.X
Caused by: java.lang.ClassNotFoundException: X.X.X.X
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

Could not find the main class: X.X.X.X Program will exit.

It's definitely there, it was fine 10 minutes ago and I haven't touched it.

I'm pretty sure it has something to with the automatic compiling (and perhaps code-completion features) of netbeans. Is there a way I can just reset all the internal data without moving everything to a new project. Or any other suggestions.

Lucas
  • 1,869
  • 4
  • 20
  • 36
  • Manual to clear the cache in Netbeans: https://stackoverflow.com/questions/8689780/how-to-clear-the-cache-in-netbeans – JAdel Mar 03 '22 at 09:53

6 Answers6

6

There is one Single and easy way to do it. make your compiler to compile that Program again. means just change some code like Put somecode Or print Something in between and Save it again.

and Clean and Build Project. that will happen

Right Click On Project --> Clean and Build.

and Run that Program Again.

Here we go enjoy. that would be solved.

in short you need to make some change so that compiler needs to compile that program again. so that error will be slolved.

and its not coding mistake i think problem is with IDE.

Kishan Bheemajiyani
  • 3,429
  • 5
  • 34
  • 68
4

In cases described, it usually helps me to delete whole cache of Netbeans.
So close Netbeans.
Locate directory with netbeans cache and delete its content.
It's usually located in [USER_HOME]\.netbeans\7.x\var - delete everything in var directory.

Ondrej Bozek
  • 10,987
  • 7
  • 54
  • 70
4

On windows 10 NetBeans 8.1, closing NetBeans, deleting the Cache directory and restarting solved this issue for me:

Cache is located at:

C:\Users\%UserName%\AppData\Local\NetBeans\Cache\

Note: I could also turn off project property, build, compiling, "Save on Compile" and the program would continue to run properly.

DSlomer64
  • 4,234
  • 4
  • 53
  • 88
Dave
  • 41
  • 1
3

Sometimes it also helps if you disable "Compile on Save".

  • Go to (Project) Properties -> Compile -> Compile on Save

(Tested with Netbeans 8.1, when clearing the cache as suggested by @Ondrej Bozek did not resolve the issue).

After running the program, you can enable "Compile on Save" again without any problems.

rmuller
  • 12,062
  • 4
  • 64
  • 92
0

This is happened to me randomly and I fixed it by renaming the class that is throwing the error, then renamed in back.

Sam Orozco
  • 1,258
  • 1
  • 13
  • 27
0

If you have any kind of crazy "can't find Class" errors that you KNOW are bogus because you didn't do anything to class names or locations and the project worked fine ten minutes ago and the error occurred after some innocuous change you made in one of the class files, then, yes, close NetBeans and delete the Cache folder. It's perfectly safe to do so.

Thw cache (Netbeans 8.2, Windows 10) is located at the path below. Note: typing exactly what's below should work for anyone, as long as UserName is a valid environment variable name.

C:\Users\%UserName%\AppData\Local\NetBeans\Cache

P.S. If UserName is not defined properly, you'll get an error. So then Run cmd and type UserName=followed by your C:\Users folder name. Let's say it's Dov. Do this:

C:...>set UserName=DOV {this sets my username to "DOV"}

C:...>set UserName {this just asks for what UserName is)

USERNAME=DOV {this says, "Hey, your UserName is "DOV"}

P.P.S. If you're not sure of your UserName, then issue the command below:

C:...>set UserProfile

USERPROFILE=C:\Users\Dov

Your Username is the last folder name listed, which is "Dov".

P.P.P.S. You've probably noticed that cAsE doesn't matter.

DSlomer64
  • 4,234
  • 4
  • 53
  • 88