无法编译的源代码

无法编译的源代码

本文介绍了“无法编译的源代码"netbeans 中的运行时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试帮助另一位使用 Netbeans 的开发人员.当他在 Netbeans (6.9.1) 中运行或调试他的一些代码时,他得到一个不可编译的源代码"RuntimeException.我在 Java 方面很有经验,但更习惯于 IntelliJ,根本没有使用过 Netbeans.

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 会编译代码,即使有错误,然后在错误处抛出 RuntimeException.(IMO 的行为相当糟糕,但我想有些人会发现它很有用.)我让他完全重建项目,没有编译错误,但 RuntimeException 似乎仍然发生.我猜他在 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.

2 个问题:

  1. 清除缓存以便我们找出不可编译代码的最佳方法是什么?
  2. 有什么办法可以关闭这种行为,这样代码就不会运行/调试,除非一切都能编译,所以这些 RuntimeException 不会被注入到代码中?

我在谷歌上搜索了很多,但还没有找到这些问题的答案.

I've googled a fair bit, but haven't found the answer to either of these questions yet.

更新:更多信息:

  1. 关闭保存时编译"选项会使问题消失.再次打开 CoS 会使异常恢复.不幸的是,这不是解决办法,因为 CoS 是一个非常有用的选项.
  2. http://netbeans.org/bugzilla/show_bug.cgi?id=182009最接近的错误报告,但它已被关闭为已解决不完整".不幸的是,这个错误很难重现——异常发生在 Java 库代码中,当它调用第三方库时,所以在抛出异常时没有任何东西可以改变.并且代码会运行数周,然后突然开始抛出这个错误,没有明显的原因.
  3. 我们尝试手动删除整个构建目录 - 仍然没有修复.
  1. 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.
  2. http://netbeans.org/bugzilla/show_bug.cgi?id=182009 seems 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.
  3. We've tried manually deleting the entire build directory - still not a fix.

推荐答案

我们终于有了解决方案,但还是不太明白为什么会出现这种情况.当您激活 Compile On Save 时,Netbeans 会生成第二组用于调试等的类文件.这些文件存储在 $USER/.netbeans/var/cache/index/s*/java/*/classes

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.

如果您关闭 netbeans,请删除 $USER/.netbeans/var/cache/index 和所有子目录并重新启动 netbeans,这将清除缓存.如果您没有编译错误,那么此时您的问题应该会消失.

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.

注意:$USER 是您的用户目录 - 在 Windows 7 上这通常是 c:Usersusername,我猜在 Unix 上它将是 ~username.

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

如果您遇到此问题,请投票、评论或添加信息到:http://netbeans.org/bugzilla/show_bug.cgi?id=182009

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

这篇关于“无法编译的源代码"netbeans 中的运行时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 07:35