java.lang.IllegalArgumentException:provider = network

时间:2014-05-07 09:18:21

标签: java android android-intent geolocation

我的Android应用程序有时会抛出此异常:

java.lang.IllegalArgumentException: provider=network
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2517)
at android.app.ActivityThread.access$1900(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1302)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4784)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:845)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: provider=network
at android.os.Parcel.readException(Parcel.java:1429)
at android.os.Parcel.readException(Parcel.java:1379)
at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:657)
at android.location.LocationManager._requestLocationUpdates(LocationManager.java:686)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:508)

在这一行:

    mLocationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, mNetlocListener);

我做错了什么?

我使用网络枚举提供程序。

1 个答案:

答案 0 :(得分:2)

首先检查是否已启用LocationManagers NETWORK_PROVIDER

if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
       mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,mNetlocListener);
    }