Java com.sun.jdi.InvocationException 发生调用方法

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

com.sun.jdi.InvocationException occurred invoking method

javaspring

提问by xyy

I just want to create an object of class, but got this error when debugging. Can anybody tell me what the problem is? The location of this code is in some Spring(2.5) Service class.

我只想创建一个类的对象,但在调试时出现此错误。谁能告诉我问题是什么?此代码的位置在某个 Spring(2.5) 服务类中。

There is a similar problem: OJB Reference Descriptor 1:0 relationship? Should I set auto-retrieve to false?

还有一个类似的问题:OJB Reference Descriptor 1:0 关系?我应该将自动检索设置为 false 吗?

Thanks a lot~

非常感谢~

回答by Frank

The root cause is that when debugging the java debug interface will call the toString() of your class to show the class information in the pop up box, so if the toString method is not defined correctly, this may happen.

根本原因是在调试的时候java调试接口会调用你的类的toString()在弹出框中显示类信息,所以如果toString方法没有正确定义,就有可能出现这种情况。

回答by stepthom

I also had a similar exception when debugging in Eclipse. When I moused-over an object, the pop up box displayed an com.sun.jdi.InvocationExceptionmessage. The root cause for me was not the toString()method of my class, but rather the hashCode()method. It was causing a NullPointerException, which caused the com.sun.jdi.InvocationExceptionto appear during debugging. Once I took care of the null pointer, everything worked as expected.

在 Eclipse 中调试时,我也遇到了类似的异常。当我将鼠标悬停在一个对象上时,弹出框会显示一条com.sun.jdi.InvocationException消息。对我来说,根本原因不是toString()我班级的hashCode()方法,而是方法。它导致了NullPointerException,这导致了com.sun.jdi.InvocationException在调试期间出现。一旦我处理了空指针,一切都按预期进行。

回答by monal86

so I had same problem here. Found out that my domain instance was getting detached from the hibernate session. I used isAttached()to check and attached the domain using d.attach()

所以我在这里遇到了同样的问题。发现我的域实例与休眠会话分离。我曾经使用isAttached()过检查和附加域d.attach()

回答by clr

Disabling 'Show Logical Structure' button/icon of the upper right corner of the variables window in the eclipse debugger resolved it, in my case.

在我的例子中,禁用 Eclipse 调试器中变量窗口右上角的“显示逻辑结构”按钮/图标解决了这个问题。

回答by arin

For me the same exception was thrown when the toString was defined as such:

对我来说,当 toString 定义为这样时,抛出了相同的异常:

@Override
public String toString() {
    return "ListElem [next=" + next + ", data=" + data + "]";
}

Where ListElemis a linked list element and I created a ListElemas such:

ListElem链表元素在哪里,我创建了一个ListElem这样的:

private ListElem<Integer> cyclicLinkedList = new ListElem<>(3);
ListElem<Integer> cyclicObj = new ListElem<>(4);
...

cyclicLinkedList.setNext(new ListElem<Integer>(2)).setNext(cyclicObj)
    .setNext(new ListElem<Integer>(6)).setNext(new ListElem<Integer>(2)).setNext(cyclicObj);

This effectively caused a cyclic linked list that cannot be printed. Thanks for the pointer.

这有效地导致了无法打印的循环链表。谢谢指点。

回答by novice

Well, it might be because of several things as mentioned by others before and after. In my case the problem was same but reason was something else.

嗯,可能是因为之前和之后其他人提到的几件事。在我的情况下,问题是一样的,但原因是别的。

In a class (A), I had several objects and one of object was another class (B) with some other objects. During the process, one of the object (String) from class B was null, and then I tried to access that object via parent class (A).

在一个类(A)中,我有几个对象,其中一个对象是另一个类(B)和其他一些对象。在此过程中,B 类的对象(String)之一为空,然后我尝试通过父类(A)访问该对象。

Thus, console will throw null point exceptionbut eclipse debugger will show above mentioned error.

因此,控制台将抛出空点异常,但 Eclipse 调试器将显示上述错误。

I hope you can do the remaining.

我希望你能做剩下的。

回答by user3257891

There could be two reasons an element doesn't exist:

元素不存在可能有两个原因:

  1. Bad xpath (//*[@id'forgotQuote])
  2. Correct xpath but no element (//*[contains(text(),'This text is not in the page')])
  1. 错误的 xpath (///*[@id'forgotQuote])
  2. 正确的 xpath 但没有元素 (///*[contains(text(),'This text is not in the page')])

Would you get com.sun.jdi.InvocationException in either case when you are running Debug and you hover your mouse over a reference to the WeBElement (this with Selenium and Java)???

在任何一种情况下,当您运行 Debug 并将鼠标悬停在对 WebElement 的引用上时,您会得到 com.sun.jdi.InvocationException 吗?(使用 Selenium 和 Java)?

We use the following, but can't distinguish if it returns false due to bad xpath or non-existent element (valid xpath syntax):

我们使用以下内容,但无法区分是否由于错误的 xpath 或不存在的元素(有效的 xpath 语法)而返回 false:

public static boolean isElementDisplayed(WebElement element) {
    boolean isDisplayed = false;

    try {
        isDisplayed = element.isDisplayed();
    } catch (NoSuchElementException e) {
        ;// No Worries
    }
    return isDisplayed;
}

回答by Praneeth

Removing hashCode()and equals()solved my issue. In my case, I used Apache's commons-lang hash code and equals builders for creating non-static classes manually, so the compiler didn't throw any exception. But at runtime it caused the invocation exception.

删除hashCode()equals()解决了我的问题。就我而言,我使用 Apache 的 commons-lang 哈希代码和 equals 构建器手动创建非静态类,因此编译器没有抛出任何异常。但是在运行时它导致了调用异常。

回答by Praneeth

I had the same issue once. In my case toString() method was badly created. TO be precise a static final variable was included in the toString method when a developer form my team was assigned code cleaning task and to add toString(), hashCode() code and equals() methods to domain objects where ever possible. but in of the classes because of over looking at it, he included final static variable that caused the "com.sun.jdi.InvocationException" this exception was visible on debugging only when I hovered over the object which has the exception.

我曾经遇到过同样的问题。就我而言, toString() 方法创建不当。准确地说,当我的团队的开发人员被分配代码清理任务并尽可能将 toString()、hashCode() 代码和 equals() 方法添加到域对象时,toString 方法中包含了一个静态最终变量。但是在类中,由于过度查看,他包含了导致“com.sun.jdi.InvocationException”的最终静态变量,只有当我将鼠标悬停在具有异常的对象上时,该异常才在调试时可见。

回答by Gloria Rampur

In my case it was due to the object reference getting stale. I was automating my application using selenium webdriver, so i type something into a text box and then it navigates to another page, so while i come back on the previous page , that object gets stale. So this was causing the exception, I handled it by again initialising the elements - PageFactory.initElements(driver, Test.class;

在我的情况下,这是由于对象引用变得陈旧。我正在使用 selenium webdriver 自动化我的应用程序,所以我在文本框中输入了一些东西,然后它导航到另一个页面,所以当我回到上一页时,该对象变得陈旧。所以这导致了异常,我通过再次初始化元素来处理它 - PageFactory.initElements(driver, Test.class;