Home > Uncategorized > “Uncompilable source code” exception in NetBeans

“Uncompilable source code” exception in NetBeans


If your project builds fine but then crashes with a runtime exception when it hits a block of code, the problem is probably with the “Compile on save” option. Right click on your project, choose Properties, Build -> Compiling. Uncheck Compile on Save. Manually build the project. When you re-run the code, the errors should go away.

Not sure what causes this, but it’s immensely frustrating and seemingly non-deterministic. Wish I had a better solution than this, but I don’t.

Edit:

I found perhaps a better solution on StackOverflow:

We finally got a solution, but still don’t quite know why the situation occurs. When you have Compile On Save activated, Netbeans generates a second set of class files for debugging etc. These are stored in $USER/.netbeans/var/cache/index/s*/java/*/classes

Somehow (not sure how) this directory can get corrupted or fail to update.

If you close netbeans, delete $USER/.netbeans/var/cache/index and all subdirectories and restart netbeans this clears the cache. If you have no compile errors, your problem ought to go away at this point.

NB: $USER is your user directory – on Windows 7 this is usually c:\Users\username, I guess on Unix it will be ~username.

If you get this problem please vote for, comment on, or add information to: http://netbeans.org/bugzilla/show_bug.cgi?id=182009

Thanks to Nick Fortescue for this information.

About these ads
  1. PP
    May 31, 2010 at 7:15 am | #1

    I was bitten by this today, and I too have no idea why it happens. This tip did make it go away, though; much appreciated. :-)

  2. trv
    August 30, 2010 at 6:51 pm | #2

    Thanks man, it helped! I really had no clue what causes this error.

  3. TrueLogic
    September 19, 2010 at 5:08 pm | #3

    I have a fix for you!
    Your workaround worked for me, but it made editing a pain, so I went back to the web and found a fix.
    Go to the line that’s giving the error and remove the returns from that area, making one long line, then put the returns back!
    Looks like netbeans is putting some hidden junk characters there.
    Hope this helps.

    • i82much
      September 20, 2010 at 3:12 pm | #4

      I’ll have to try that one out. Thanks for the info.

  4. Nick Fortescue
    December 8, 2010 at 8:55 am | #5

    If you are interested I’ve found a slightly better solution to this. I’ve added it at: http://stackoverflow.com/questions/4386076/uncompilable-source-code-runtimeexception-in-netbeans

    • i82much
      December 8, 2010 at 2:48 pm | #6

      Hey Nick – thanks for the link. I hope the NetBeans developers realize that this is a serious issue and put some resources behind fixing it.

  5. Cool Guy
    August 17, 2011 at 5:14 pm | #7

    Badass that fixed my problem Thanks

  6. August 31, 2011 at 5:20 pm | #8

    Thanks man, fixed the problem

  7. Mauricio Daste
    September 7, 2011 at 10:11 am | #9

    Una maquina la respuesta..!!

  8. Sushant
    November 27, 2012 at 10:43 pm | #10

    Thanks it worked for me :)

  9. flowjames
    January 28, 2013 at 10:55 am | #11

    Thanks for the post. This seems to still be an issue with NetBeans IDE 7.2 Beta (Build 201205031832). It may be time to update.

  1. March 12, 2011 at 6:51 pm | #1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: