我正在使用列表适配器,我正在尝试对其进行设置,以便在单击列表视图中的项目时发生反应(将覆盖项目设置为在所选项目中可见),我想做的是单击另一个项目时,先前单击的项目不可见。问题是我遇到了以下崩溃:
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.lists.MainAdapter$1.onClick(MainAdapter.java:106)
at android.view.View.performClick(View.java:4102)
at android.view.View$PerformClick.run(View.java:17126)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
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:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
它发生在以下代码中:
holder.image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("image click");
holder.grid_overlay.setVisibility(View.VISIBLE);
if(!(lastView == 0)){
View item = holder.grid_overlay.getChildAt(lastView);
if(item.getVisibility() == View.VISIBLE){
item.setVisibility(View.GONE);
}
System.out.println("before update "+lastView);
}
lastView = Integer.valueOf(holder.encase.getTag().toString());
System.out.println("after update "+lastView);
}
});
问题似乎指向以下行:
if(item.getVisibility() == View.VISIBLE){
有人可以帮忙吗?谢谢 :)