Java IntelliJ - 没有这样的实例方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21487219/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 08:58:42  来源:igfitidea点击:

IntelliJ - No such instance method

javascalaintellij-idea

提问by Kevin Meredith

Using IntelliJ's 12 Ultimate, I'm running the following code in the Debugger:

使用 IntelliJ 的 12 Ultimate,我在调试器中运行以下代码:

Java

爪哇

import play.api.libs.json.JsValue;
public class Foo { 
 ...
 public JsValue toJson() { ... }

public class FooExample {
...
  Foo foo = new Foo(); 
  System.out.println("...); //<-- breakpoint

At the breakpoint, I right-clicked my source code and picked "Evaluate Expression," typing in:

在断点处,我右键单击我的源代码并选择“评估表达式”,输入:

foo.toJson().

foo.toJson().

But the following error showed up:

但是出现了以下错误:

No such instance method: play.api.libs.json.JsValue$class.com.foo.Foo.toJson ()

No such instance method: play.api.libs.json.JsValue$class.com.foo.Foo.toJson ()

Am I doing something wrong? Foo#toJsoncalls Scala code, if that matters.

难道我做错了什么?Foo#toJson调用 Scala 代码,如果这很重要的话。

EDITI actually had the breakpoint after the instantiation of Foo.To those who downvoted it, I deserved it.

编辑我实际上在实例化之后有断点Foo.对于那些拒绝它的人,我应得的。

回答by Javaru

EDIT

编辑

My answer is no longer valid after OP modified question (i.e. moved where the breakpoint actual is)..

在 OP 修改问题(即移动断点实际所在的位置)后,我的答案不再有效。

A breakpoint is hit before the line is executed. So in this case foohas not yet been declared or instantiated (i.e. the Fooconstructor has not yet been called). You'll need to put the breakpoint at the next line (or step over the current line) if you want to evaluate foo.

在执行该行之前命中一个断点。所以在这种情况下foo还没有被声明或实例化(即Foo尚未调用构造函数)。如果要评估foo.

回答by moralejaSinCuentoNiProverbio

I have the same exception message In IntelliJ 2017.1.3 at debugging time.

我在调试时在 IntelliJ 2017.1.3 中有相同的异常消息。

That happens to me when I tried to access an inexistent method for the instance, not for the class.

当我尝试访问实例的不存在方法而不是类时,就会发生这种情况。

Common example: If you forget to deploy your code to the server and your class have a new method when you are debugging you can't watch new members nor evaluate new methods.

常见示例:如果您忘记将代码部署到服务器并且您的类在调试时有一个新方法,您将无法观察新成员或评估新方法。

Regards.

问候。

回答by LazerBass

I ran into that issue trying to call org.jdbi.v3.core.result.ResultIterable#onein the Evaluate expressionwindow during a debugging session. IntelliJ showed the following error message

我在调试会话期间尝试org.jdbi.v3.core.result.ResultIterable#oneEvaluate 表达式窗口中调用时遇到了这个问题。IntelliJ 显示以下错误消息

No such instance method: 'one'

没有这样的实例方法:'one'

while the code was just running fine when I did not have a debugger attached.

当我没有附加调试器时,代码运行良好。

It turned out that my Project language levelin IntelliJ was no set properly (can be set under Project settings -> Project).

原来我在 IntelliJ 中的Project 语言级别设置不正确(可以在 Project settings -> Project 下设置)。

The onemethod is implemented as a defaultmethodin an interface. My JAVA_HOMEwas properly set to a JDK 12 but the Project language level was set to 6. After adjusting the Project language level to 12 the error was gone and I could step through the method.

one方法被实现为default方法中的接口。我的JAVA_HOME正确设置为 JDK 12,但项目语言级别设置为 6。将项目语言级别调整为 12 后,错误消失了,我可以逐步完成该方法。