java.lang.IllegalArgumentException:provider不存在:null

时间:2014-01-10 02:30:00

标签: android gps

我正在制作Android应用程序。 我使用ACRA来获取崩溃报告。 在很多报道中,我有这个例外...... 但对我来说,它始终有效,我无法重现它。

API可以是15,17等......

以下是我的GPS管理文件:

public class ConectUtils {     private final String TAG = getClass()。getSimpleName();

private Context ctx;
private LocationManager locationManager;

public ConectUtils(Context ctx) {
    super();
    this.ctx = ctx;
    locationManager = (LocationManager) ctx
            .getSystemService(Context.LOCATION_SERVICE);
}

public boolean isConnectingToInternet() {
    ConnectivityManager connectivity = (ConnectivityManager) ctx
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null)
            for (int i = 0; i < info.length; i++)
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }

    }
    return false;
}

public boolean start() {
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

    } else {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                ctx);
        alertDialogBuilder
                .setMessage(R.string.gps_disabled)
                .setCancelable(false)
                .setPositiveButton("Enable GPS",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                MapActivity.hasClickedGpsChange = true;
                                Intent callGPSSettingIntent = new Intent(
                                            android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                    ctx.startActivity(callGPSSettingIntent);

                            }
                        });
        alertDialogBuilder.setNegativeButton(R.string.cancel,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        MapActivity.hasClickedGpsChange = true;
                        dialog.cancel();
                    }
                });
        AlertDialog alert = alertDialogBuilder.create();
        alert.show();

    }
    return true;
}

public LocationListener getGpsLocationListener() {
    return gpsLocationListener;
}

public LocationManager getLocationManager() {
    return locationManager;
}

public void setLocationManager(LocationManager locationManager) {
    this.locationManager = locationManager;
}

public LocationListener getNetworkLocationListener() {
    return networkLocationListener;
}

private final LocationListener gpsLocationListener = new LocationListener() {

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        switch (status) {
        case LocationProvider.AVAILABLE:
            Log.e(TAG, "GPS available again\n");
            break;
        case LocationProvider.OUT_OF_SERVICE:
            Log.e(TAG, "GPS out of service\n");
            break;
        case LocationProvider.TEMPORARILY_UNAVAILABLE:
            Log.e(TAG, "GPS temporarily unavailable\n");
            break;
        }
    }

    @Override
    public void onProviderEnabled(String provider) {
        Log.e(TAG, "GPS Provider Enabled\n");
    }

    @Override
    public void onProviderDisabled(String provider) {
        Log.e(TAG, "GPS Provider Disabled\n");
    }

    @Override
    public void onLocationChanged(Location location) {

        Log.v(TAG, "New GPS location: " + location.getLatitude() + ", "
                + location.getLongitude());
        // Se manda la ubicacion actual a MapActivity
        sendBroadCast(location);

    }
};

private final LocationListener networkLocationListener = new LocationListener() {

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        switch (status) {
        case LocationProvider.AVAILABLE:
            Log.e(TAG, "Network available again\n");
            break;
        case LocationProvider.OUT_OF_SERVICE:
            Log.e(TAG, "Network location out of service\n");
            break;
        case LocationProvider.TEMPORARILY_UNAVAILABLE:
            Log.e(TAG, "Network location temporarily unavailable\n");
            break;
        }
    }

    @Override
    public void onProviderEnabled(String provider) {
        Log.e(TAG, "Network Provider Enabled\n");
    }

    @Override
    public void onProviderDisabled(String provider) {
        Log.e(TAG, "Network Provider Disabled\n");
    }

    @Override
    public void onLocationChanged(Location location) {
        Log.e(TAG,
                "New network location: "
                        + String.format("%9.6f", location.getLatitude())
                        + ", "
                        + String.format("%9.6f", location.getLongitude())
                        + "\n");

        sendBroadCast(location);

    }

};

private void sendBroadCast(Location location) {

    Intent locationAlert = new Intent(
            "com.xoco.pemex.checker.LOCATION_CHANGED").putExtra(
            "target_location", location);
    ctx.sendBroadcast(locationAlert);
}
public void addUpdates(LocationListener gpsLocationListener,
        LocationListener networkLocationListener) {
    locationManager.requestLocationUpdates(
            LocationManager.NETWORK_PROVIDER, 0, 0,
            networkLocationListener);
    locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 0, 0, gpsLocationListener);
}



public void removeUpdates(LocationListener gpsLocationListener,
        LocationListener networkLocationListener) {
    locationManager.removeUpdates(gpsLocationListener);
    locationManager.removeUpdates(networkLocationListener);
}

}

如果可以提供帮助,我会加入完整的ACRA报告:

USER_EMAIL = N/A
USER_COMMENT = 
SETTINGS_GLOBAL = 
DEVICE_FEATURES = android.hardware.location.network
android.hardware.location
android.hardware.touchscreen.multitouch.jazzhand
android.hardware.touchscreen.multitouch
android.hardware.screen.landscape
android.hardware.screen.portrait
android.hardware.sensor.compass
android.hardware.faketouch
android.hardware.camera
android.hardware.bluetooth
android.hardware.touchscreen.multitouch.distinct
android.hardware.microphone
android.hardware.camera.autofocus
android.hardware.sensor.accelerometer
android.hardware.touchscreen
glEsVersion = 0.0

PHONE_MODEL = Nexus S
SETTINGS_SECURE = ACCESSIBILITY_SCRIPT_INJECTION=0
ACCESSIBILITY_SPEAK_PASSWORD=0
ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS=0x13=0x01000100; 0x14=0x01010100; 0x15=0x02000001; 0x16=0x02010001; 0x200000013=0x02000601; 0x200000014=0x02010601; 0x200000015=0x03020101; 0x200000016=0x03010201; 0x200000023=0x02000301; 0x200000024=0x02010301; 0x200000037=0x03070201; 0x200000038=0x03000701:0x03010701:0x03020701;
ALLOW_MOCK_LOCATION=1
ANDROID_ID=67391168c9fb7a9c
ASSISTED_GPS_ENABLED=1
BACKUP_ENABLED=1
BACKUP_PROVISIONED=1
BACKUP_TRANSPORT=android/com.android.internal.backup.LocalTransport
BLUETOOTH_ON=0
CDMA_CELL_BROADCAST_SMS=1
DATA_ROAMING=0
DEFAULT_INPUT_METHOD=com.android.inputmethod.latin/.LatinIME
DEVICE_PROVISIONED=1
ENABLED_INPUT_METHODS=com.android.inputmethod.latin/.LatinIME:com.android.inputmethod.pinyin/.PinyinIME:com.example.android.softkeyboard/.SoftKeyboard:jp.co.omronsoft.openwnn/.OpenWnnJAJP
INPUT_METHODS_SUBTYPE_HISTORY=
INSTALL_NON_MARKET_APPS=1
LOCATION_PROVIDERS_ALLOWED=gps
LONG_PRESS_TIMEOUT=500
MOUNT_PLAY_NOTIFICATION_SND=1
MOUNT_UMS_AUTOSTART=0
MOUNT_UMS_NOTIFY_ENABLED=1
MOUNT_UMS_PROMPT=1
NETWORK_PREFERENCE=1
PREFERRED_CDMA_SUBSCRIPTION=1
PREFERRED_NETWORK_MODE=0
SELECTED_INPUT_METHOD_SUBTYPE=-1
SELECTED_SPELL_CHECKER=com.android.inputmethod.latin/.spellcheck.AndroidSpellCheckerService
SELECTED_SPELL_CHECKER_SUBTYPE=0
THROTTLE_RESET_DAY=17
TOUCH_EXPLORATION_ENABLED=0
USB_MASS_STORAGE_ENABLED=1
WIFI_COUNTRY_CODE=us
WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON=1
WIFI_ON=0

INSTALLATION_ID = e0cbe915-eaf0-4aa9-b398-54451890a0a1
SETTINGS_SYSTEM = ACCELEROMETER_ROTATION=1
AIRPLANE_MODE_ON=0
AIRPLANE_MODE_RADIOS=cell,bluetooth,wifi,nfc,wimax
AIRPLANE_MODE_TOGGLEABLE_RADIOS=bluetooth,wifi,nfc
ALARM_ALERT=content://media/internal/audio/media/23
AUTO_TIME=1
AUTO_TIME_ZONE=1
CALL_AUTO_RETRY=0
CAR_DOCK_SOUND=/system/media/audio/ui/Dock.ogg
CAR_UNDOCK_SOUND=/system/media/audio/ui/Undock.ogg
DESK_DOCK_SOUND=/system/media/audio/ui/Dock.ogg
DESK_UNDOCK_SOUND=/system/media/audio/ui/Undock.ogg
DIM_SCREEN=1
DOCK_SOUNDS_ENABLED=0
DTMF_TONE_TYPE_WHEN_DIALING=0
DTMF_TONE_WHEN_DIALING=1
EMERGENCY_TONE=0
HAPTIC_FEEDBACK_ENABLED=1
HEARING_AID=0
LOCKSCREEN_SOUNDS_ENABLED=1
LOCK_SOUND=/system/media/audio/ui/Lock.ogg
LOW_BATTERY_SOUND=/system/media/audio/ui/LowBattery.ogg
MODE_RINGER=2
MODE_RINGER_STREAMS_AFFECTED=166
MUTE_STREAMS_AFFECTED=46
NEXT_ALARM_FORMATTED=
NOTIFICATION_LIGHT_PULSE=1
NOTIFICATION_SOUND=content://media/internal/audio/media/138
POINTER_SPEED=0
POWER_SOUNDS_ENABLED=1
RINGTONE=content://media/internal/audio/media/30
SCREEN_BRIGHTNESS=102
SCREEN_BRIGHTNESS_MODE=0
SCREEN_OFF_TIMEOUT=60000
SOUND_EFFECTS_ENABLED=1
STAY_ON_WHILE_PLUGGED_IN=1
TRANSITION_ANIMATION_SCALE=1.0
TTY_MODE=0
UNLOCK_SOUND=/system/media/audio/ui/Unlock.ogg
VIBRATE_IN_SILENT=1
VIBRATE_ON=10
VOLUME_ALARM=6
VOLUME_BLUETOOTH_SCO=7
VOLUME_MUSIC=11
VOLUME_NOTIFICATION=5
VOLUME_RING=5
VOLUME_SYSTEM=7
VOLUME_VOICE=4
WINDOW_ANIMATION_SCALE=1.0

SHARED_PREFERENCES = default.acra.lastVersionNr=16


IS_SILENT = 
ANDROID_VERSION = 4.0.4
PACKAGE_NAME = com.xoco.pemex.checker
APP_VERSION_CODE = 16
CRASH_CONFIGURATION = compatScreenHeightDp=508
compatScreenWidthDp=320
compatSmallestScreenWidthDp=320
fontScale=1.0
hardKeyboardHidden=HARDKEYBOARDHIDDEN_YES
keyboard=KEYBOARD_NOKEYS
keyboardHidden=KEYBOARDHIDDEN_NO
locale=en_US
mcc=310
mnc=260
navigation=NAVIGATION_TRACKBALL
navigationHidden=NAVIGATIONHIDDEN_NO
orientation=ORIENTATION_PORTRAIT
screenHeightDp=508
screenLayout=SCREENLAYOUT_SIZE_NORMAL+SCREENLAYOUT_LONG_YES
screenWidthDp=320
seq=5
smallestScreenWidthDp=320
textLayoutDirection=0
touchscreen=TOUCHSCREEN_FINGER
uiMode=UI_MODE_TYPE_NORMAL+UI_MODE_NIGHT_NO
userSetLocale=true

USER_CRASH_DATE = 2012-10-09T19:04:53.000+02:00
DUMPSYS_MEMINFO = Permission Denial: can\'t dump meminfo from from pid=1510, uid=10039 without permission android.permission.DUMP

BUILD = BOARD=herring
BOOTLOADER=I9020XXLC2
BRAND=google
CPU_ABI=armeabi-v7a
CPU_ABI2=armeabi
DEVICE=crespo
DISPLAY=JRO03E
FINGERPRINT=google/soju/crespo:4.1.1/JRO03E/403059:user/release-keys
HARDWARE=herring
HOST=vpba16.mtv.corp.google.com
ID=JRO03E
IS_DEBUGGABLE=true
MANUFACTURER=samsung
MODEL=Nexus S
PRODUCT=soju
RADIO=unknown
SERIAL=323316ED529F00EC
TAGS=release-keys
TIME=1334746257000
TYPE=user
UNKNOWN=unknown
USER=android-build
VERSION.CODENAME=REL
VERSION.INCREMENTAL=eng.juntian.20120418.185032
VERSION.RELEASE=4.0.4
VERSION.RESOURCES_SDK_INT=15
VERSION.SDK=15
VERSION.SDK_INT=15

STACK_TRACE = java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xoco.pemex.checker/com.xoco.pemex.checker.MapActivity}: java.lang.IllegalArgumentException: provider=network
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
    at android.app.ActivityThread.access$600(ActivityThread.java:123)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    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:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: provider=network
    at android.os.Parcel.readException(Parcel.java:1331)
    at android.os.Parcel.readException(Parcel.java:1281)
    at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:646)
    at android.location.LocationManager._requestLocationUpdates(LocationManager.java:589)
    at android.location.LocationManager.requestLocationUpdates(LocationManager.java:453)
    at com.xoco.pemex.checker.a.a(ConectUtils.java:186)
    at com.xoco.pemex.checker.MapActivity.onCreate(MapActivity.java:140)
    at android.app.Activity.performCreate(Activity.java:4465)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
    ... 11 more
java.lang.IllegalArgumentException: provider=network
    at android.os.Parcel.readException(Parcel.java:1331)
    at android.os.Parcel.readException(Parcel.java:1281)
    at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:646)
    at android.location.LocationManager._requestLocationUpdates(LocationManager.java:589)
    at android.location.LocationManager.requestLocationUpdates(LocationManager.java:453)
    at com.xoco.pemex.checker.a.a(ConectUtils.java:186)
    at com.xoco.pemex.checker.MapActivity.onCreate(MapActivity.java:140)
    at android.app.Activity.performCreate(Activity.java:4465)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
    at android.app.ActivityThread.access$600(ActivityThread.java:123)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    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:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)

PRODUCT = soju
DISPLAY = 0.height=800
0.orientation=0
0.pixelFormat=4
0.getRealSize=[480,800]
0.rectSize=[0,0,480,800]
0.refreshRate=260.416
0.rotation=ROTATION_0
0.getSize=[480,800]
0.width=480

LOGCAT = 
APP_VERSION_NAME = 1.1.2
AVAILABLE_MEM_SIZE = 193474560
USER_APP_START_DATE = 2012-10-09T19:04:53.000+02:00
CUSTOM_DATA = 
BRAND = google
INITIAL_CONFIGURATION = compatScreenHeightDp=508
compatScreenWidthDp=320
compatSmallestScreenWidthDp=320
fontScale=1.0
hardKeyboardHidden=HARDKEYBOARDHIDDEN_YES
keyboard=KEYBOARD_NOKEYS
keyboardHidden=KEYBOARDHIDDEN_NO
locale=en_US
mcc=310
mnc=260
navigation=NAVIGATION_TRACKBALL
navigationHidden=NAVIGATIONHIDDEN_NO
orientation=ORIENTATION_PORTRAIT
screenHeightDp=508
screenLayout=SCREENLAYOUT_SIZE_NORMAL+SCREENLAYOUT_LONG_YES
screenWidthDp=320
seq=5
smallestScreenWidthDp=320
textLayoutDirection=0
touchscreen=TOUCHSCREEN_FINGER
uiMode=UI_MODE_TYPE_NORMAL+UI_MODE_NIGHT_NO
userSetLocale=true

TOTAL_MEM_SIZE = 203423744
FILE_PATH = /data/data/com.xoco.pemex.checker/files
ENVIRONMENT = getDataDirectory=/data
getDownloadCacheDirectory=/cache
getExternalStorageAndroidDataDir=/mnt/sdcard/Android/data
getExternalStorageDirectory=/mnt/sdcard
getExternalStorageState=mounted
getRootDirectory=/system
getSecureDataDirectory=/data
getSystemSecureDirectory=/data/system
isEncryptedFilesystemEnabled=false
isExternalStorageEmulated=false
isExternalStorageRemovable=false

REPORT_ID = 817c517d-7b16-4d56-8847-23d1c3a2fdc7
编辑:可能在这里有一个线索 Runtime Error--java.lang.IllegalArgumentException: provider=gps

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:5)

我通过检查是否已启用LocationManagers NETWORK_PROVIDER来解决此问题

if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

我认为你在模拟器中尝试测试......

您是否在Real Device上尝试过相同的代码?我认为它应该适用于设备,网络提供商会在模拟器上造成问题。