eclipse 错误!非静态 Java 函数“replace”的第一个参数不是有效的对象引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10607151/
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
Error! The first argument to the non-static Java function 'replace' is not a valid object reference
提问by user1397000
I am trying to get ANT to create an HTML report of a JUNIT test in Eclipse but after I created the ANT build I get the following errors when I run it:
我试图让 ANT 在 Eclipse 中创建 JUNIT 测试的 HTML 报告,但是在我创建 ANT 构建之后,我在运行它时收到以下错误:
[junitreport] Processing C:\Documents and Settings\Administrator\workspace\Home\junit\TESTS-TestSuites.xml to C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\null785926900
[junitreport] Loading stylesheet jar:file:/C:/ANT/apache-ant-1.8.3/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] : Error! The first argument to the non-static Java function 'replace' is not a valid object reference.
[junitreport] : Error! Cannot convert data-type 'void' to 'reference'.
[junitreport] : Fatal Error! Could not compile stylesheet
[junitreport] Failed to process C:\Documents and Settings\Administrator\workspace\Home\junit\TESTS-TestSuites.xml
What do I need to do to fix this?
我需要做什么来解决这个问题?
Here are the sections of my Build.xml I am trying to run:
以下是我尝试运行的 Build.xml 部分:
<target name="Home">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="Home" todir="${junit.output.dir}"/>
<classpath refid="Home.classpath"/>
</junit>
</target>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
回答by Kal
When I got this error I had to right click on my build.xml file in Eclipse, choose the "Run as Ant build..." option (3rd one in the menu) then click the JRE tab and select the "Run in the same JRE as the workspace" option and then proceeded to run the script. For some reason this fixed the problem. I honestly don't know why.
当我收到这个错误时,我必须在 Eclipse 中右键单击我的 build.xml 文件,选择“Run as Ant build...”选项(菜单中的第三个),然后单击 JRE 选项卡并选择“Run in the与工作区相同的 JRE”选项,然后继续运行脚本。出于某种原因,这解决了问题。老实说,我不知道为什么。
回答by MikeBach
The Eclipse Bug is clearly documented Bug 384757. The analysis suggests that Oracle introduced the bug. I need Java version 7 but JunitReport needs Java version 5 and early versions of Java version 6. The obvious way is to add the "bootclasspath" argument to the Ant junitreport task while the Java problem is fixed by Oracle in a future release. Unfortunately Ant task junitreport does not support the bootclasspath option. Is this something the people supporting Ant could do?
Eclipse 错误是明确记录的错误 384757。分析表明,Oracle 引入了该错误。我需要 Java 版本 7,但 JunitReport 需要 Java 版本 5 和 Java 版本 6 的早期版本。显而易见的方法是将“bootclasspath”参数添加到 Ant junitreport 任务,而 Java 问题在未来版本中由 Oracle 修复。不幸的是 Ant 任务 junitreport 不支持 bootclasspath 选项。这是支持 Ant 的人可以做的事情吗?
回答by Charles Wu
I met this situation while running my java program on Ubuntu 12.04with *java 1.7.0_51* on Eclipse SDK Juno. I take Bhagyaraj's suggestion which is using apache-ant-1.9.2 instead. (p.s. The default ant version of Eclipse Juno is *org.apache.ant_1.8.3*, and I use apache-ant-1.9.3)
我在Eclipse SDK Juno上使用 *java 1.7.0_51* 在Ubuntu 12.04上运行我的 java 程序时遇到了这种情况。我接受 Bhagyaraj 的建议,即改用 apache-ant-1.9.2。(ps Eclipse Juno默认的ant版本是*org.apache.ant_1.8.3*,我用的是apache-ant-1.9.3)
You may following my steps to setup.
您可以按照我的步骤进行设置。
- Download apache-ant-1.9.3-bin.zip and extract to a place where you want.
- Open your eclipse and choose Window --> Preferences
- You can see the Preferences window. On the left hand side please choose ant --> runtime
- Now focus on right hand-site of the window. Make sure you are now on Classpathtab and choose Ant Home Entries(Default).The buttons on the right which is Ant Home...is now click-able.
- No doubt, click on Ant Home...button and choose the folder where your ant-1.9.3 is. In this step, if you choose wrong folder, Eclipse may show the error message something like Specified Ant home does not contain a "lib" directory. If you choose the right directory, Ant Home Entries(Default)will become **Ant Home Entries()
- Don't forget to click apply.
- 下载 apache-ant-1.9.3-bin.zip 并解压到你想要的地方。
- 打开你的 eclipse 并选择 Window --> Preferences
- 您可以看到“首选项”窗口。在左侧,请选择 ant --> runtime
- 现在专注于窗口的右侧站点。确保您现在位于Classpath选项卡上并选择Ant Home Entries(Default)。右侧的按钮是Ant Home...现在可以单击。
- 毫无疑问,单击Ant Home...按钮并选择您的 ant-1.9.3 所在的文件夹。在这一步中,如果您选择了错误的文件夹,Eclipse 可能会显示类似Specified Ant home does not contain a "lib" directory的错误消息。如果选择正确的目录,Ant Home Entries(Default)将变成**Ant Home Entries()
- 不要忘记单击应用。
After change those, while you right click on build.xml file and choose Run --> 1 Ant Build, the error message won't show because your ant is now 1.9.3.
更改这些之后,当您右键单击 build.xml 文件并选择 Run --> 1 Ant Build 时,将不会显示错误消息,因为您的 ant 现在是 1.9.3。
I also download apache-ant-1.8.4 to run my build file, but the error can't be solved.
我也下载了apache-ant-1.8.4来运行我的build文件,但是错误无法解决。
回答by Bhagyaraj
I used the jdk1.6.45 and latest apache-ant-1.9.2-bin\
我使用了 jdk1.6.45 和最新的 apache-ant-1.9.2-bin\
Problem solved.
问题解决了。
As per note on MikeBach
根据 MikeBach 上的说明
This is bug#, please read: https://bugs.eclipse.org/bugs/show_bug.cgi?id=384757Fixed in Ant.
这是错误#,请阅读:https: //bugs.eclipse.org/bugs/show_bug.cgi?id =384757 已在 Ant 中修复。
Regards, Bhagyaraj
问候, Bhagyaraj
回答by J?rg
The Bugwas introduced in Java 7u5 according to this comment. Another commentexplains how to workaround it, changing the bootclasspath. (DISCLAIMER: I didn't try and test this.)
根据此注释,该错误是在 Java 7u5 中引入的。另一条评论解释了如何解决它,更改bootclasspath。(免责声明:我没有尝试测试这个。)
This solution, however, workedfine for me:
但是,此解决方案对我来说效果很好:
- Download ant-1.9.4
- Eclipse>>Preferences>>Ant>>Runtime>>AntHomeEntries
- Remove all 1.8.x classpath entries
- Add all libs from 1.9.4 instead
- 下载ant-1.9.4
- Eclipse>>首选项>>Ant>>运行时>>AntHomeEntries
- 删除所有 1.8.x 类路径条目
- 改为添加 1.9.4 中的所有库
According to Ant Changes, this has been fixed since 1.9.1
回答by user1444020
If you are using Eclipse/JUnit report with JDK 1.7, please use JDK 1.6. There is a bug in JDK 1.7 with Eclipse/JUnit report similar to what you describe. This may be a similar report: https://netbeans.org/bugzilla/show_bug.cgi?id=201022
如果您在 JDK 1.7 中使用 Eclipse/JUnit 报告,请使用 JDK 1.6。JDK 1.7 中有一个错误,Eclipse/JUnit 报告类似于您所描述的。这可能是类似的报告:https: //netbeans.org/bugzilla/show_bug.cgi?id=201022
回答by jm0
I've tried using a few different JRE/JDK settings (all 1.6 and 1.7) with various problems (this or lack of access to XSL file in jar) for each.
我已经尝试使用一些不同的 JRE/JDK 设置(所有 1.6 和 1.7),每个设置都有各种问题(这个或无法访问 jar 中的 XSL 文件)。
It's not a perfect solution obviously but I don't seem to run into these issues if the JUnit report is "raw" in the buildfile -- not wrapped in a target.
显然,这不是一个完美的解决方案,但如果 JUnit 报告在构建文件中是“原始的”——而不是包含在目标中,我似乎不会遇到这些问题。
Poor workaround obviously in that targets are an important aspect of Ant but sometimes for reporting build targets/dependencies aren't so mission critical. It's not so much of an issue for me yet because I'm running these reports in kindof a one-off fashion rather than as part of a build.
糟糕的解决方法显然是因为目标是 Ant 的一个重要方面,但有时报告构建目标/依赖项并不是那么关键的任务。这对我来说还不是什么大问题,因为我正在以一种一次性的方式运行这些报告,而不是作为构建的一部分。