I want when a user clicks on "ans_three_btn_one" button than a dialog appears and in that dialogbox, I want to implement rorate animation on sunburst imageview. The only problem in this code is "sunburst.startAnimation". If I remove this line then code work properly but no animation. With this line of code my app crashing. Appreciate If you help me.
public class GamePlay extends AppCompatActivity implements View.OnClickListener {
Button ans_three_btn_one;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_play);
ans_three_btn_one = findViewById(R.id.ans_three_first_btn);
ans_three_btn_one.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Dialog first_prize_dialog = new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
first_prize_dialog.setContentView(R.layout.activity_first_prize);
first_prize_dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
first_prize_dialog.show();
ImageView sunbrust = findViewById(R.id.sunbrust_img);
//----Error area start ---
sunbrust.startAnimation(AnimationUtils.loadAnimation(v.getContext(),R.anim.rotate));
//----Error area end ---
}
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.startAnimation(android.view.animation.Animation)' on a null object reference
Application terminated.