错误呼吁NPObject方法!在安卓2.2 [英] Error calling method on NPObject! in Android 2.2

查看:245
本文介绍了错误呼吁NPObject方法!在安卓2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用addJavascriptInterface在我的Andr​​oid应用程序,以允许JavaScript调用功能,我在我的本地Java应用程序创建的。

I'm using addJavascriptInterface within my Android application to allow JavaScript to invoke functions I've created in my native Java application.

这在Android 2.1的效果很好,但是在Android 2.2的我收到错误信息错误呼吁NPObject方法!

This worked well in Android 2.1, however in Android 2.2 I receive the error message "Error calling method on NPObject!"

在我的仪器方法调用本地方法的内部越来越调用,但是除了正在扔在JavaScript中。

When I instrument the method call the internals of the native method are getting called, however the exception is being throw in JavaScript.

推荐答案

我得到这个确切的错误:

I was getting this exact error:

未捕获的错误:NPObject错误调用的方法!

Uncaught Error: Error calling method on NPObject!

原来我试图从像这样一个web视图调用JavascriptInterface功能:

Turns out I was attempting to invoke a JavascriptInterface function from a webview like so:

AndroidJS.populateField(场);

AndroidJS.populateField(field);

和在Java端,该功能并没有接受一个参数:

and on the Java side, the function didn't accept a parameter:

公共无效populateField(){}

public void populateField() {}

简单地允许Java函数接受一个参数为我解决了这个错误。

Simply allowing the Java function to accept a parameter solved this error for me.

如, 公共无效populateField(String字段){}

E.g., public void populateField(String field) {}

这可能不是,也许不是,可能会抛出这个错误的唯一原因。这是我简单的如何解决我的具体方案。希望这可以帮助! :)

This may not be, and probably is not, the only reason this error could be thrown. This is simply how I resolved my specific scenario. Hope this helps! :)

这篇关于错误呼吁NPObject方法!在安卓2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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