NPE for Custom ListView中的按钮

时间:2013-01-27 08:30:50

标签: android android-listview

我有自定义列表视图,每个单元格有5个textviews和2个按钮。不知何故,当我滚动时,我在getView方法中为按钮获取NPE。粘贴日志

01-27 08:15:40.654: D/AndroidRuntime(15471): Shutting down VM
01-27 08:15:40.654: W/dalvikvm(15471): threadid=1: thread exiting with uncaught     exception (group=0x40c181f8)
01-27 08:15:40.662: E/AndroidRuntime(15471): FATAL EXCEPTION: main
01-27 08:15:40.662: E/AndroidRuntime(15471): java.lang.NullPointerException
01-27 08:15:40.662: E/AndroidRuntime(15471):    at  com.example.collegesoft.ViewAttendance$MyAdapter.getView(ViewAttendance.java:158)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.widget.AbsListView.obtainView(AbsListView.java:2189)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.widget.ListView.makeAndAddView(ListView.java:1772)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.widget.ListView.fillDown(ListView.java:672)
 01-27 08:15:40.662: E/AndroidRuntime(15471):   at android.widget.ListView.fillGap(ListView.java:636)
 01-27 08:15:40.662: E/AndroidRuntime(15471):   at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5312)
 01-27 08:15:40.662: E/AndroidRuntime(15471):   at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3050)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.widget.AbsListView.onTouchEvent(AbsListView.java:3391)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.View.dispatchTouchEvent(View.java:5588)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1962)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1723)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1968)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1737)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1968)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1737)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1968)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1737)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1968)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1737)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at   com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2060)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1398)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2008)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.View.dispatchPointerEvent(View.java:5768)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2957)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2531)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:898)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2540)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.os.Looper.loop(Looper.java:137)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at android.app.ActivityThread.main(ActivityThread.java:4514)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at java.lang.reflect.Method.invokeNative(Native Method)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at java.lang.reflect.Method.invoke(Method.java:511)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
01-27 08:15:40.662: E/AndroidRuntime(15471):    at dalvik.system.NativeStart.main(Native Method)

任何帮助将不胜感激。 Lemme知道你是否想要代码。

感谢名单

1 个答案:

答案 0 :(得分:0)

我找到了答案。这是一个愚蠢的错误。对于我以前使用setId()方法的按钮。然后我把它改成setTag(),一切都像魅力一样。

Thanx反正