error尝试调用虚方法'android.location.Location

时间:2015-12-14 10:04:25

标签: javascript angularjs local-storage ibm-mobilefirst mobilefirst-geolocation

我正在使用MobileFirst提供的WL.Device.Geo.acquirePosition(onGeoLocationSuccess,onGeoLocationFailure,options)检索设备的位置。

第一次工作正常。我得到了位置,一切都很好。

但是,在应用程序的某一点上,我清除了localStorage。当我这样做时,应用程序变得疯狂,我在控制台中不断收到此错误:

getPosition - error Attempt to invoke virtual method 'android.location.Location com.worklight.androidgap.plugin.WLGPSListener.getLastKnownLocation()' on a null object reference

这就是我的代码的样子:

position();

function position() {

  var options = {
    enableHighAccuracy : false,
    timeout            : 20000,
    maximumAge         : 30000,
    highAccuracyOptions: {
      desiredAccuracy: 50, //meters
      iOSBestAccuracy: WL.Device.Geo.IOS_BEST_ACCURACY
    }
  };

  WL.Device.Geo.acquirePosition(onGeoLocationSuccess, onGeoLocationFailure, options);
}

function onGeoLocationSuccess(position) {
  WL.Logger.info('Got position now ;)');
}

function onGeoLocationFailure(errorObj) {
  console.log('Trying again ');
  position();
}

这就是我在其他服务中重置localStorage的方式

localStorage.clear();

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

localStorage的

Check for the contents;由于您强制清除整个存储,我怀疑您在应用程序的运行时清除了所需的数据。

只清除你需要清理的东西,而不是全部清除。

相关问题