java.lang.IllegalArgumentException:provider==null

发布于 2024-12-19 19:10:19 字数 1609 浏览 1 评论 0原文

我的类有问题,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离笑几人歌 2024-12-26 19:10:19

这是因为该行

   String mejorProvider = locManager.getBestProvider(criterio, true);

导致 mejorProvider 为 null。是什么导致了这个空值?很难说。您请求的提供商不存在,或者您可能尚未在清单中启用请求用户位置的权限。

It's because this line

   String mejorProvider = locManager.getBestProvider(criterio, true);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文