求大神指导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)

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

5个回答

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

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

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

android.content.Intent.migrateExtraStreamToClipData()'

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

仔细检查。

boolean android.content.Intent.migrateExtraStreamToClipData()是因为intent没有初始化

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问