我在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 };
}
这是堆栈跟踪:
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)
最佳答案
删除行super.onListItemClick(l, v, position, id);