删除ImageView会导致某些手机崩溃

时间:2012-09-27 04:49:22

标签: android android-imageview

因此,出于某种原因,在我的Samsung Galaxy S2(Android版本4.0.4)尝试从RelativeLayout中删除ImageView时,我得到了一个N​​PE。这是运行的代码行

mainView.removeView(someImageView)

然而,在我的Galaxy Nexus(Android版本4.1.1)上,它甚至没有打嗝。我在下面发布了NPE。这不是删除ImageView的正确方法吗?基本上我完成了图像,我不再需要它了。任何想法或想法都会很棒。

FATAL EXCEPTION: main
java.lang.NullPointerException
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2488)
at android.view.View.draw(View.java:11150)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:11150)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.View.draw(View.java:11150)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.ViewGroup.drawChild(ViewGroup.java:2885)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.ViewGroup.drawChild(ViewGroup.java:2885)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:11150)
at android.widget.FrameLayout.draw(FrameLayout.java:450)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2302)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2127)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1733)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2545)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
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:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
!@Dumpstate > dumpstate -k -t -n -z -d -o /data/log/dumpstate_app_error

编辑:我认为这与问题没有任何关系,但是在翻译动画的“onAnimationEnd”方法中删除了这个。

1 个答案:

答案 0 :(得分:5)

尝试将imageView的可见性设置为GONE,如:

someImageView.setVisibility(View.GONE);