RelativeLayout (動的) でビューを削除しようとすると、メッセージ エラー - 強制終了 - が表示されます。
add view : (レイアウトはrelativelayout、Sunanimの拡張ビュー)
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)
私はそれを修正する必要がありますか?