import android.app.Activity;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
public class Ball extends Activity
{
private String name; //Red, Blue, Violet, Green
private int rand;
ImageView img;
RelativeLayout rel = (RelativeLayout)findViewById(R.id.GameView);
public Ball(int num)
{
rand = (int)(Math.random() * 500 + 1);
img = new ImageView(this);
img.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
setName(num);
Animation ani = new TranslateAnimation(rand, rand, -500, 1700);
ani.setDuration(5000);
img.setAnimation(ani);
status = "S";
speed = 10000;
}
public void setName(int num)
{
switch(num)
{
case 1:
this.name = "Red";
img.setBackgroundResource(R.drawable.red);
rel.addView(img);
break;
case 2:
this.name = "Blue";
img.setBackgroundResource(R.drawable.blue);
rel.addView(img);
break;
case 3:
this.name = "Green";
img.setBackgroundResource(R.drawable.green);
rel.addView(img);
break;
case 4:
this.name = "Violet";
img.setBackgroundResource(R.drawable.violet);
rel.addView(img);
break;
}
}
}
위 소스코드의 Ball 객체를 메인 액티비티에서
Ball ball = new Ball(1);
이렇게 호출을 햇더니 계속 널포인트익셉션이 뜹니다.. 도대체 뭐가문제인지 모르겠습니다...