java.lang.IllegalArgumentException:provider==null
我的类有问题,log cat 在运行时返回此错误
12-05 23:19:18.299: E/AndroidRuntime(15460): Caused by: java.lang.IllegalArgumentException: provider==null
12-05 23:19:18.299: E/AndroidRuntime(15460): at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1017)
12-05 23:19:18.299: E/AndroidRuntime(15460): at com.rbrlnx.lugares.editarLugar.onCreate(editarLugar.java:110)
12-05 23:19:18.299: E/AndroidRuntime(15460): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-05 23:19:18.299: E/AndroidRuntime(15460): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
并且代码是
/************************************************************************************
*
* Creamos un location manager, le establecemos unos criterios minimos para encontra
*
***********************************************************************************/
LocationManager locManager = (LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criterio = new Criteria();
criterio.setAccuracy(Criteria.ACCURACY_COARSE);
String mejorProvider = locManager.getBestProvider(criterio, true);
//Obtenemos la última posición conocida
final Location loc = locManager.getLastKnownLocation(mejorProvider);
latitud = loc.getLatitude();
longitud= loc.getLongitude();
//Me centro en el mapa
yo = new GeoPoint(
(int)(latitud*1000000),
(int)(longitud*1000000));
仅设置最佳提供者并获取最后的已知位置但它崩溃了,有人知道为什么吗?
I have a problem with a class, log cat return this error when a run
12-05 23:19:18.299: E/AndroidRuntime(15460): Caused by: java.lang.IllegalArgumentException: provider==null
12-05 23:19:18.299: E/AndroidRuntime(15460): at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1017)
12-05 23:19:18.299: E/AndroidRuntime(15460): at com.rbrlnx.lugares.editarLugar.onCreate(editarLugar.java:110)
12-05 23:19:18.299: E/AndroidRuntime(15460): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-05 23:19:18.299: E/AndroidRuntime(15460): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
And the code is
/************************************************************************************
*
* Creamos un location manager, le establecemos unos criterios minimos para encontra
*
***********************************************************************************/
LocationManager locManager = (LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criterio = new Criteria();
criterio.setAccuracy(Criteria.ACCURACY_COARSE);
String mejorProvider = locManager.getBestProvider(criterio, true);
//Obtenemos la última posición conocida
final Location loc = locManager.getLastKnownLocation(mejorProvider);
latitud = loc.getLatitude();
longitud= loc.getLongitude();
//Me centro en el mapa
yo = new GeoPoint(
(int)(latitud*1000000),
(int)(longitud*1000000));
Only set the best provider and get the last know position but it crash, anyone knows why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为该行
导致
mejorProvider
为 null。是什么导致了这个空值?很难说。您请求的提供商不存在,或者您可能尚未在清单中启用请求用户位置的权限。It's because this line
results in
mejorProvider
being null. What caused that null? Hard to tell. Either the provider you asked for does not exist or maybe you haven't enabled permissions in your manifest for requesting the user's location.