Phonegap build geolocation Error calling method on NPObject

泄露秘密 提交于 2019-12-24 19:26:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!