【问题标题】:Android Emulator: Illegal Argument Exception Null at Location ProviderAndroid 模拟器:位置提供程序处的非法参数异常 Null
【发布时间】:2014-06-23 01:36:15
【问题描述】:

该应用程序将在我的真实设备上正常运行,但与在我的真实设备上运行一样 模拟器,它立即崩溃,我收到一条错误消息,指出 GPS 坐标为空。即使在打开 DDMS,运行应用程序,然后发送坐标并尝试登录之后,将调用 onCreate 方法来查找 GPS,它仍然会显示 null 错误(下)

我创建的所有模拟器都允许 GPS,但错误仍然存​​在。首先需要 GPS 的 onCreate 代码如下:

// Ensuring a location, loop till find it

do {
    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the location provider -> use
    // default
    Criteria criteria = new Criteria();
    provider = locationManager.getBestProvider(criteria, false);
    Location location = locationManager.getLastKnownLocation(provider);

// Just test displaying
lat = (float) (location.getLatitude());
lng = (float) (location.getLongitude());

} while (lat == 0.0);

具体报错信息为:

java.lang.IllegalArgumentException: invalid provider: null at android.location.LocationManager.checkProvider(LocationManager.java:1623)

【问题讨论】:

    标签: android android-emulator gps illegalargumentexception


    【解决方案1】:

    在 android 模拟器上,您从 locationManager.getBestProvider(criteria, false); 获得 null 提供程序

    查看此帖子:https://stackoverflow.com/a/20661039/4387543

    【讨论】:

      猜你喜欢
      • 2016-12-23
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      • 1970-01-01
      • 2013-06-07
      • 2011-12-12
      • 1970-01-01
      • 2012-11-13
      相关资源
      最近更新 更多