0

我有一个自定义列表视图,每个单元格有 5 个文本视图和 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)

任何帮助,将不胜感激。让我知道你是否想要 c 代码。

谢谢

4

1 回答 1

0

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

无论如何谢谢

于 2013-01-31T10:24:06.783 回答