Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 350
Kevin Meredith Avatar asked Feb 13 '23 22:02

Kevin Meredith


2 Answers

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.

like image 160
Javaru Avatar answered Feb 24 '23 00:02

Javaru


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.

like image 21
brass monkey Avatar answered Feb 24 '23 01:02

brass monkey