Error calling method on NPObject! in Android 2.2

后端 未结 6 645
轻奢々
轻奢々 2021-01-11 16:45

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

This worked well

6条回答
  •  半阙折子戏
    2021-01-11 17:01

    I had the same problem with Javascript-to-Java interface (WebView.addJavascriptInterface).

    In Android 2.1 everything worked just fine but in Android 2.2 Javascript failed to call methods from this interface. It returned an error: Uncaught Error: Error calling method on NPObject!

    It seems that on Android 2.2, the WebView has problem with Boolean data type returned from interface functions.

    Changing:

    public Boolean test_func() { return true; }
    

    ... to:

    public int test_func() { return 1; }
    

    ... solved the problem.

提交回复
热议问题