onListItemClick上的NullPointerException

时间:2011-11-28 22:16:06

标签: java android nullpointerexception listactivity android-activity

我在ListActivity中随机获得nullpointerexception(我无法一致地重现错误)。 StackTrace在第一行super.onListItemClick()上显示错误。不知道为什么这会返回null?

@Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        for (int i = 0; i < infos.size(); i++)
            if (i != position)
                l.getChildAt(i).setBackgroundColor(0xFF444444);
        v.setBackgroundColor(0xFF666666);
        // v.setClickable(true);
        // test.setColorFilter(Color.parseColor("#444444"),
        // PorterDuff.Mode.DARKEN);
        ApplicationInfo ai = null;
        ai = infos.get(position);
        rinfos = findActivitiesForPackage(this, ai.packageName);
        ResolveInfo ri = rinfos.get(0);
        app_package_and_name = new String[] { ri.activityInfo.packageName, ri.activityInfo.name };
    }

这是stacktrace:

java.lang.NullPointerException
at com.sonrlabs.test.sonr.SONR.onListItemClick(SONR.java:189)
at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3763)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1936)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
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)

1 个答案:

答案 0 :(得分:3)

删除第super.onListItemClick(l, v, position, id);