Java netbeans 中的“无法编译的源代码”运行时异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4386076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Uncompilable source code" RuntimeException in netbeans
提问by Nick Fortescue
I'm trying to help another developer who is using Netbeans. When he runs or debugs some code of his in Netbeans (6.9.1) he gets an "Uncompilable source code" RuntimeException
. I'm pretty experienced in Java but am more used to IntelliJ, and haven't used Netbeans at all.
我正在尝试帮助另一个使用 Netbeans 的开发人员。当他在 Netbeans (6.9.1) 中运行或调试他的一些代码时,他得到一个“不可编译的源代码” RuntimeException
。我在 Java 方面很有经验,但更习惯于 IntelliJ,根本没有使用过 Netbeans。
I've done it a bit of googling and it seems Netbeans will compile code even with errors, and then throw the RuntimeException
at the errors. (Fairly bad behaviour IMO, but I guess some will find it useful.) I've got him to completely rebuild the project with no compile errors, but the RuntimeException
seems to still occur. I assume he's got some bad cached class data somewhere deep within Netbeans.
我已经做了一些谷歌搜索,似乎 Netbeans 即使有错误也会编译代码,然后抛出RuntimeException
错误。(IMO 的行为相当糟糕,但我想有些人会发现它很有用。)我让他完全重建项目,没有编译错误,但RuntimeException
似乎仍然发生。我假设他在 Netbeans 深处的某个地方有一些不好的缓存类数据。
2 questions:
2个问题:
- What is the best way to clear the cache so we can find out where the uncompilable code is?
- Is there any way of turning off this behaviour so the code won't run/debug unless everything will compile, so these RuntimeException's won't be injected into the code?
- 清除缓存以便我们找出不可编译代码的最佳方法是什么?
- 有没有办法关闭这种行为,这样代码就不会运行/调试,除非一切都能编译,所以这些 RuntimeException 不会被注入到代码中?
I've googled a fair bit, but haven't found the answer to either of these questions yet.
我在谷歌上搜索了很多,但还没有找到这些问题的答案。
Update: More information:
更新:更多信息:
- Turning off the "compile on save" option makes the problem go away. Turning CoS back on again brings the exception back. Unfortunately this isn't a fix, as CoS is a very useful option.
- http://netbeans.org/bugzilla/show_bug.cgi?id=182009seems the closest bug report, but it has been closed as "RESOLVED INCOMPLETE". Unfortunately the bug is hard to reproduce - the exception is happening in Java library code, when it calls a third-party library, so there isn't anything at the point the exception is thrown we can change. And the code will work for weeks, and then suddenly start throwing this error with no obvious reason why.
- We've tried manually deleting the entire build directory - still not a fix.
- 关闭“保存时编译”选项会使问题消失。再次打开 CoS 会使异常恢复。不幸的是,这不是解决办法,因为 CoS 是一个非常有用的选项。
- http://netbeans.org/bugzilla/show_bug.cgi?id=182009似乎是最接近的错误报告,但它已被关闭为“已解决不完整”。不幸的是,这个错误很难重现——异常发生在 Java 库代码中,当它调用第三方库时,所以在抛出异常时没有任何东西可以改变。并且代码将工作数周,然后突然开始抛出这个错误,没有明显的原因。
- 我们已经尝试手动删除整个构建目录 - 仍然没有修复。
采纳答案by Nick Fortescue
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
我们终于得到了解决方案,但仍然不太明白为什么会出现这种情况。当您激活 Compile On Save 时,Netbeans 会生成第二组用于调试等的类文件。这些文件存储在$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.
如果您关闭 netbeans、删除$USER/.netbeans/var/cache/index
所有子目录并重新启动 netbeans,这将清除缓存。如果您没有编译错误,那么此时您的问题应该会消失。
NB: $USER is your user directory - on Windows 7 this is usually c:\Users\username
, I guess on Unix it will be ~username
.
注意:$USER 是您的用户目录 - 在 Windows 7 上这通常是c:\Users\username
,我猜在 Unix 上它会是~username
.
If you get this problem please vote for, comment on, or add information to: http://netbeans.org/bugzilla/show_bug.cgi?id=182009
如果您遇到此问题,请投票、评论或添加信息到:http: //netbeans.org/bugzilla/show_bug.cgi?id=182009
回答by Szymon
I experienced the same wired problem in NB 7.0.1, my hammer-IQ solution was to make a typo in the source code, run NB with this error (despite an error message) and than the cached class was successfully deleted.
我在 NB 7.0.1 中遇到了同样的有线问题,我的hammer-IQ 解决方案是在源代码中打错字,在出现此错误的情况下运行 NB(尽管有错误消息),然后成功删除了缓存类。
回答by Amitabh Choudhury
In fact, you neednt delete whole of index folder. When you open netbeans and your project folder is active. Netbeans starts scanning files and creates temporary project folders (in index folder) for all active projects. If you check index\segments file(its a text file and can be viewed in notepad/(text editor)), you will be able to identify the folders that represent your project. You can then delete those folders and restart netbeans.
事实上,您不需要删除整个索引文件夹。当您打开 netbeans 并且您的项目文件夹处于活动状态时。Netbeans 开始扫描文件并为所有活动项目创建临时项目文件夹(在索引文件夹中)。如果您检查 index\segments 文件(它是一个文本文件,可以在记事本/(文本编辑器)中查看),您将能够识别代表您项目的文件夹。然后您可以删除这些文件夹并重新启动 netbeans。
*Active project means those projects that were open before Netbeans was shutdown.
*活动项目是指在关闭 Netbeans 之前打开的那些项目。
回答by StackExchange What The Heck
I experienced this issue on Linux Mint Nadia with Netbeans 7.2.1, but was stumped as to where the cache location might be - mine was actually located at
我在使用 Netbeans 7.2.1 的 Linux Mint Nadia 上遇到了这个问题,但对缓存位置可能在哪里感到困惑 - 我的实际上位于
/home/USER/.cache/netbeans/7.2.1
rather than in the .netbeans folder.
而不是在 .netbeans 文件夹中。
If you're not sure where the cache is located on your particular setup, just go to the help > about menu in Netbeans and it'll tell you the correct path.
如果您不确定缓存在特定设置中的位置,只需转到 Netbeans 中的帮助 > 关于菜单,它就会告诉您正确的路径。
回答by Tom Anderson
After realising that the cause was a bad cache from the other posted solutions, I solved this problem by copying the file to another directory, deleting it from NetBeans, and then adding it again.
在意识到原因是其他发布的解决方案中的缓存错误后,我通过将文件复制到另一个目录,从 NetBeans 中删除它,然后再次添加它来解决这个问题。