无法从页面调用小程序方法 [英] Trouble calling an applet method from page

查看:46
本文介绍了无法从页面调用小程序方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道它不是最佳的,但我必须使用它,一个调用小程序的页面.

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]."

有人能解码吗?甚至多种可能性都会比我想出的垃圾更好.对小程序的基本调用来自 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?

推荐答案

InvocationTargetException 表示您的小程序中的底层方法抛出了异常.Javascript 到 Java 的边界"使用反射,因此 Java 代码抛出的异常是这样包装的.(这样就可以将它们与在您进入 Java 代码之前抛出的异常区分开来.例如,如果您尝试调用一个不存在的方法.)

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).

这篇关于无法从页面调用小程序方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆