问题
I have a problem with the phonegap/cordova geolocation plugin. I'm creating a application that uses the users geolocation to check if they are close to a position and then do some stuff with that.
I kept getting this error: Error calling method on NPObject. I moved the code around and created some new functions to have more specific functions and found the failing code.
I put it in a try ... catch to get better errors:
getLocation: function()
{
try
{
navigator.geolocation.getCurrentPosition(this.onSuccess, this.onError);
}
catch(err)
{
console.log("Error code: "+err.code);
console.log("Error message: "+err.message);
}
}
But I still only get the same error Error code: undefined Error message: Error calling method on NPObject.
I'm using phonegap build and have added the plugin for geolocation.
回答1:
It happens when you try, using method called from javascript interface, to interact with UI. Solve it in this way:
class mJSInterface()
{
public void myFunction()
{
runOnUiThread(new Runnable() {
public void run() {
//Code that interact with UI
}
});
}
}
来源:https://stackoverflow.com/questions/19832398/phonegap-build-geolocation-error-calling-method-on-npobject