【发布时间】: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