'IntelliJ - No such instance method
Using IntelliJ's 12 Ultimate, I'm running the following code in the Debugger:
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().
But the following error showed up:
No such instance method: play.api.libs.json.JsValue$class.com.foo.Foo.toJson ()
Am I doing something wrong? Foo#toJson calls Scala code, if that matters.
EDIT I actually had the breakpoint after the instantiation of Foo. To those who downvoted it, I deserved it.
Solution 1:[1]
EDIT
My answer is no longer valid after OP modified question (i.e. moved where the breakpoint actual is)..
A breakpoint is hit before the line is executed. So in this case foo has not yet been declared or instantiated (i.e. the Foo constructor 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.
Solution 2:[2]
I ran into that issue trying to call org.jdbi.v3.core.result.ResultIterable#one in the Evaluate expression window during a debugging session.
IntelliJ showed the following error message
No such instance method: 'one'
while the code was just running fine when I did not have a debugger attached.
It turned out that my Project language level in IntelliJ was no set properly (can be set under Project settings -> Project).
The one method is implemented as a default method in an interface.
My JAVA_HOME was 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.
Solution 3:[3]
I have the same exception message In IntelliJ 2017.1.3 at debugging time.
That happens to me when I tried to access an nonexistent 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | brass monkey |
| Solution 3 | Mark Rotteveel |
