2 mengjiacun mengjiacun 于 2016.01.20 12:00 提问

求大神指导Android 空指针异常问题

代码如下:
private OnPreferenceClickListener mPrefClickListener = new OnPreferenceClickListener() {

    @Override
    public boolean onPreferenceClick(Preference preference) {
        Intent intent = preference.getIntent();
        try {
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(getActivity(), R.string.plugin_app_unavailable, Toast.LENGTH_LONG).show();
            Log.w(TAG, preference.getKey() + " not available", e);
        }

        return true;
    }
};

    log 如下:
    01-19 06:34:24.911  6327  6327 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData()' on a null object reference

01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1622)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.app.Activity.startActivityFromFragment(Activity.java:4548)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.app.Activity.startActivityFromFragment(Activity.java:4510)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.app.Fragment.startActivity(Fragment.java:1086)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.app.Fragment.startActivity(Fragment.java:1065)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at com.lenovo.settings.CharSettings$2.onPreferenceClick(CharSettings.java:114)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.preference.Preference.performClick(Preference.java:1015)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:214)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.widget.AdapterView.performItemClick(AdapterView.java:310)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.widget.AbsListView.performItemClick(AbsListView.java:1188)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.widget.AbsListView$PerformClick.run(AbsListView.java:3231)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.widget.AbsListView$3.run(AbsListView.java:4165)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:815)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:104)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.os.Looper.loop(Looper.java:194)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5731)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
01-19 06:34:24.911 6327 6327 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

求大神指教,小白一枚,谢谢

4个回答

caozhy
caozhy   Ds   Rxr 2016.01.20 12:08

boolean android.content.Intent.migrateExtraStreamToClipData()
仔细调试这里,有对象引用是null

slandkiss
slandkiss   2016.01.20 13:14

intent缺少action或者extra这些,这就根据你的意图了

crazy1235
crazy1235   Ds   Rxr 2016.02.01 13:46

android.content.Intent.migrateExtraStreamToClipData()'

说你这个方法**空引用了**。

仔细检查。

91program
91program   Ds   Rxr 2016.01.20 12:05

Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData()' on a null object reference
这个 migrateExtraStreamToClipData 函数是在哪里调用的?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!