java.lang.IllegalArgumentException上的错误:provider == null

时间:2022-02-17 20:51:26

I published my application to android market. I got error in my home page. Somebody wrote crash error. But this application is perfectly working in my real device. I added permission also. My error:

我将我的应用程序发布到了android市场。我的主页出错了。有人写了崩溃错误。但是这个应用程序在我的真实设备中完美运行。我也加入了许可。我的错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.karthi.locationspeecher/com.android.locationspeecher.LocationSpeecher}: java.lang.IllegalArgumentException: provider==null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: provider==null
at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1017)
at com.android.locationspeecher.LocationSpeecher.onCreate(LocationSpeecher.java:84)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more

LocationManager:

的LocationManager:

 LocationManager locationManager; 
            String context = Context.LOCATION_SERVICE; 
            locationManager = (LocationManager)getSystemService(context); 

            Criteria crta = new Criteria(); 
            crta.setAccuracy(Criteria.ACCURACY_FINE); 
            crta.setAltitudeRequired(false); 
            crta.setBearingRequired(false); 
            crta.setCostAllowed(true); 
            crta.setPowerRequirement(Criteria.POWER_LOW); 
            String provider = locationManager.getBestProvider(crta, true); 

         // String provider = LocationManager.GPS_PROVIDER; 
            Location location = locationManager.getLastKnownLocation(provider); 
            updateWithNewLocation(location); 

            locationManager.requestLocationUpdates(provider, 2000, 10, locationListener); 
            } 

3 个解决方案

#1


6  

You are getting this error most probably, due to un-availability of GPS Providers. Please ask the person to check settings if Gps Provider or Network Provider has been enabled into Location settings.

由于GPS提供商无法使用,您最有可能收到此错误。如果Gps提供商或网络提供商已启用到位置设置,请要求此人检查设置。

#2


0  

Also make sure to add android.permission.ACCESS_FINE_LOCATION or android.permission.ACCESS_COARSE_LOCATION to your Manifest file, this solved the issue for me (all providers were already enabled in the location settings).

还要确保将android.permission.ACCESS_FINE_LOCATION或android.permission.ACCESS_COARSE_LOCATION添加到您的清单文件中,这解决了我的问题(所有提供程序已在位置设置中启用)。

#3


0  

I solved this by adding :

我通过添加:

`[assembly: UsesPermission(Manifest.Permission.AccessFineLocation)] [assembly: UsesPermission(Manifest.Permission.AccessCoarseLocation)] [assembly: UsesPermission(Manifest.Permission.Internet)]'

`[assembly:UsesPermission(Manifest.Permission.AccessFineLocation)] [assembly:UsesPermission(Manifest.Permission.AccessCoarseLocation)] [assembly:UsesPermission(Manifest.Permission.Internet)]'

in assemlyInfo.cs to give permission

在assemlyInfo.cs中给予权限

#1


6  

You are getting this error most probably, due to un-availability of GPS Providers. Please ask the person to check settings if Gps Provider or Network Provider has been enabled into Location settings.

由于GPS提供商无法使用,您最有可能收到此错误。如果Gps提供商或网络提供商已启用到位置设置,请要求此人检查设置。

#2


0  

Also make sure to add android.permission.ACCESS_FINE_LOCATION or android.permission.ACCESS_COARSE_LOCATION to your Manifest file, this solved the issue for me (all providers were already enabled in the location settings).

还要确保将android.permission.ACCESS_FINE_LOCATION或android.permission.ACCESS_COARSE_LOCATION添加到您的清单文件中,这解决了我的问题(所有提供程序已在位置设置中启用)。

#3


0  

I solved this by adding :

我通过添加:

`[assembly: UsesPermission(Manifest.Permission.AccessFineLocation)] [assembly: UsesPermission(Manifest.Permission.AccessCoarseLocation)] [assembly: UsesPermission(Manifest.Permission.Internet)]'

`[assembly:UsesPermission(Manifest.Permission.AccessFineLocation)] [assembly:UsesPermission(Manifest.Permission.AccessCoarseLocation)] [assembly:UsesPermission(Manifest.Permission.Internet)]'

in assemlyInfo.cs to give permission

在assemlyInfo.cs中给予权限