问题描述
我知道这是不是最佳的,但我有它的工作,一个网页拨打电话的小程序。
I know it's not optimal, but I have to work with it, a page making calls to the applet.
我的问题是,当我这样做,我收到一个相当神秘的错误消息:
My problem is, when I do so, I recieve a rather cryptic error message:
的未捕获的异常:错误调用方法上NPObject 的
的 [插件例外:java.lang.reflect.InvocationTargetException]。的
任何人都可以去code呢?甚至多种可能性会比我想出了更好的垃圾。以小程序的基本呼叫是从JavaScript调用:
Can anyone decode this? Even multiple possibilities would be better than the junk I came up with. The basic call to the applet is from a javascript call:
document.getElementById('my_applet').passData("pass some data", someOtherData);
正如你所看到的,passData方法是暴露的方法,我尝试使用。小程序本身工作正常网页上,它只是当我尝试调用该方法,它不这样做,除了抛出的错误东西。
As you can see, the passData method is the exposed method I am trying to use. The applet itself works fine on the page, it's just when I try to call this, it doesn't do anything except throw that error.
如果我问小程序的工作(这不是我的部分)是有可能的人对他们增加建设性错误引发或我不是即使在连接到小程序没有意义呢?
If I ask the person working on the applet (it's not my portion) is it possible for them to add constructive error throwing or am I not even at the point of connecting to the applet yet?
推荐答案
的表明,在你的applet底层方法抛出异常。的JavaScript到Java的边界使用反射,所以由Java code抛出的异常被包装这样。 (这样就可以将它们从抛出你有到你的Java code之前有例外区分。例如,如果你试图调用一个不存在的方法。)
InvocationTargetException indicates that the underlying method in your applet threw an exception. The Javascript to Java "boundary" uses reflection, so exceptions thrown by the Java code are wrapped like this. (This makes it possible to distinguish them from exceptions thrown before you got into your Java code. For example, if you tried to call a non-existant method.)
您可以通过捕获的InvocationTargetException,然后调用获取原始异常的 getTargetException()
或的getCause()
方法(它们都做同样的事情)。
You can get the original exception by catching the InvocationTargetException and then calling its getTargetException()
or getCause()
method (they both do exactly the same thing).
这篇关于麻烦从调用页面的小程序的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!