“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.
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. 🙂
Thanks man, it helped! I really had no clue what causes this error.
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.
I’ll have to try that one out. Thanks for the info.
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
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.
Badass that fixed my problem Thanks
Thanks man, fixed the problem
Una maquina la respuesta..!!
Thanks it worked for me 🙂
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.