【问题标题】:error Attempt to invoke virtual method 'android.location.Location错误尝试调用虚拟方法'android.location.Location
【发布时间】:2015-12-15 03:40:23
【问题描述】:

我正在使用 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();

有什么建议吗?

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多