Android模拟器:位置提供程序的非法参数异常空置

时间:2014-06-23 01:36:15

标签: android android-emulator gps illegalargumentexception

应用程序将在我的真实设备上正常运行但运行正常  模拟器,它立即崩溃,我收到一条错误消息,指出GPS坐标为空。即使打开DDMS,运行应用程序,然后发送坐标并尝试登录,其中onCreate方法将被调用寻找GPS,它仍然注意到空错误(下面)

我创建的所有模拟器都允许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)

1 个答案:

答案 0 :(得分:0)

在Android模拟器上,您可以从null

获得locationManager.getBestProvider(criteria, false);提供程序

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