滚动图库小部件时出现NullPointerException

时间:2011-10-05 10:11:46

标签: android gallery nullpointerexception

我有时会在使用gallery小部件时出现一个奇怪的错误(NullPointerException),它只会在有时向不同方向快速滚动时出现 - 奇怪的是,堆栈跟踪中没有我的类。

有没有人知道可能导致问题的原因是什么?

10-05 11:54:45.080: ERROR/AndroidRuntime(24935): FATAL EXCEPTION: main
10-05 11:54:45.080: ERROR/AndroidRuntime(24935): java.lang.NullPointerException
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.View.draw(View.java:6906)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.View.draw(View.java:6906)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.View.draw(View.java:6906)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1868)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.ViewRoot.draw(ViewRoot.java:1407)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.os.Looper.loop(Looper.java:123)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at android.app.ActivityThread.main(ActivityThread.java:4627)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at java.lang.reflect.Method.invokeNative(Native Method)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at java.lang.reflect.Method.invoke(Method.java:521)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
10-05 11:54:45.080: ERROR/AndroidRuntime(24935):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

是的,有时会发生。它也发生在我身上。我无法找到根本原因但我作为解决方案所做的是用try catch包装代码并使用!null检查解决了我的问题。