Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error calling method on NPObject! in Android 2.2

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 in Android 2.1, however in Android 2.2 I receive the error message "Error calling method on NPObject!"

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

like image 763
Kevin Avatar asked Jul 27 '10 13:07

Kevin


1 Answers

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

like image 80
muffs Avatar answered Oct 05 '22 08:10

muffs