ビューを削除すると、エラーが発生しました。エラーの原因がわかりません:</p>
**java:**
package com.test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
public class AnimationActivity extends Activity {
ImageView imageView = null;
ViewGroup viewGroup = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView = (ImageView)findViewById(R.id.imageviewID);
viewGroup = (ViewGroup)findViewById(R.id.layoutId);
}
public void buttonOnclick(View e){
int id = e.getId();
if(id==R.id.alpha){
AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0f);
alphaAnimation.setDuration(5000);
alphaAnimation.setStartOffset(500);
alphaAnimation.setFillAfter(true);
alphaAnimation.setFillBefore(false);
alphaAnimation.setAnimationListener(new RemoveAnimationListener());
imageView.startAnimation(alphaAnimation);
Log.d("mydebug","imageView------------>"+imageView);
Log.d("mydebug","viewGroup------------>"+viewGroup);
}
}
private class RemoveAnimationListener implements AnimationListener{
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
viewGroup.removeView(imageView);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
}
ここにエラーがあります:</p>
05-22 10:01:16.367: W/dalvikvm(1839): threadid=1: thread exiting with uncaught exception (group=0x4001d7c8)ss
05-22 10:01:16.397: E/AndroidRuntime(1839): FATAL EXCEPTION: main
05-22 10:01:16.397: E/AndroidRuntime(1839): java.lang.NullPointerException
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1366)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.View.draw(View.java:6743)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.widget.FrameLayout.draw(FrameLayout.java:352)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.View.draw(View.java:6743)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.widget.FrameLayout.draw(FrameLayout.java:352)
05-22 10:01:16.397: E/AndroidRuntime(1839): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1857)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.ViewRoot.draw(ViewRoot.java:1407)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.os.Handler.dispatchMessage(Handler.java:99)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.os.Looper.loop(Looper.java:123)
05-22 10:01:16.397: E/AndroidRuntime(1839): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-22 10:01:16.397: E/AndroidRuntime(1839): at java.lang.reflect.Method.invokeNative(Native Method)
05-22 10:01:16.397: E/AndroidRuntime(1839): at java.lang.reflect.Method.invoke(Method.java:521)
05-22 10:01:16.397: E/AndroidRuntime(1839): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-22 10:01:16.397: E/AndroidRuntime(1839): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-22 10:01:16.397: E/AndroidRuntime(1839): at dalvik.system.NativeStart.main(Native Method)