当我努力删除 RelativeLayout(动态)中的视图时,我收到一条消息错误 - 强制关闭。
添加视图:(layout是relativelayout,Sunanim的扩展View)
SunAnim rotateImg = new SunAnim(this);
rotateImg.setTag("imgsun");
layout.addView(rotateImg);
删除视图:(CloudAnim <=> SunAnim)
class CountDownRunner implements Runnable{
// @Override
public void run() {
while(!Thread.currentThread().isInterrupted()){
try {
Thread.sleep(1000);
delAnim ++;
SunAnim rotateImg = (SunAnim)layout.findViewWithTag("imgsun");
CloundAnim cl = (CloundAnim)layout.findViewWithTag("imgcl");
if (rotateImg != null && delAnim == 15) {
((RelativeLayout)rotateImg.getParent()).removeView(rotateImg);
layout.invalidate();
delAnim = 0;
Log.d("Rotate","Deleted");
}
if (cl != null && delAnim == 15) {
((RelativeLayout)cl.getParent()).removeView(cl);
layout.invalidate();
delAnim = 0;
Log.d("CL","Deleted");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}catch(Exception e){
}
}
}
}
最后 - Logcat T_T :
07-06 08:14:36.326: E/AndroidRuntime(3733): Uncaught handler: thread main exiting due to uncaught exception
07-06 08:14:36.373: E/AndroidRuntime(3733): java.lang.NullPointerException
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1255)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.View.draw(View.java:6277)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.View.draw(View.java:6277)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.View.draw(View.java:6277)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-06 08:14:36.373: E/AndroidRuntime(3733): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1883)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.ViewRoot.draw(ViewRoot.java:1332)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.ViewRoot.performTraversals(ViewRoot.java:1097)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.view.ViewRoot.handleMessage(ViewRoot.java:1613)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.os.Looper.loop(Looper.java:123)
07-06 08:14:36.373: E/AndroidRuntime(3733): at android.app.ActivityThread.main(ActivityThread.java:4203)
07-06 08:14:36.373: E/AndroidRuntime(3733): at java.lang.reflect.Method.invokeNative(Native Method)
07-06 08:14:36.373: E/AndroidRuntime(3733): at java.lang.reflect.Method.invoke(Method.java:521)
07-06 08:14:36.373: E/AndroidRuntime(3733): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
07-06 08:14:36.373: E/AndroidRuntime(3733): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
07-06 08:14:36.373: E/AndroidRuntime(3733): at dalvik.system.NativeStart.main(Native Method)
我应该修复它吗?