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

时间:2021-12-03 20:18:55

The application will run correctly on my real device just fine but as running on the emulator, it immediately crashes and I receive an error message noting that the GPS coordinates are null. Even after opening DDMS, running the application, then sending coordinates and attempting the login, where the onCreate method will be called looking for GPS, it still notes null error (below)

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

All emulators I have created allow for GPS but still the error persists. The code for onCreate where GPS is first required is below:

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

The specific error message is:

具体的错误信息是:

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

1 个解决方案

#1


0  

On android emulator you get null provider from locationManager.getBestProvider(criteria, false);

在android模拟器上,您可以从locationManager获得零提供者。getBestProvider(标准,假);

check this post: https://*.com/a/20661039/4387543

检查这篇文章:https://*.com/a/20661039/4387543

#1


0  

On android emulator you get null provider from locationManager.getBestProvider(criteria, false);

在android模拟器上,您可以从locationManager获得零提供者。getBestProvider(标准,假);

check this post: https://*.com/a/20661039/4387543

检查这篇文章:https://*.com/a/20661039/4387543