且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法从页面调用小程序方法

更新时间:2023-11-19 22:48:16

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