Error calling method on NPObject! in Android 2.2

后端 未结 6 648
轻奢々
轻奢々 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:08

    I was getting this exact error:

    Uncaught Error: Error calling method on NPObject!

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

    AndroidJS.populateField(field);

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

    public void populateField() {}

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

    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! :)

提交回复
热议问题