WelcomeToTheDarkSide :
I am having problems with my Animation drawable. It is telling me it's pointing to a null object reference, but i'm pretty sure that it isn't. How do I fix that?
Any help would be very helpful at this point! thank you!
public class PlayingScreen extends AppCompatActivity implements View.OnClickListener {
int notLike_Liked = 1;
int Pause_Play = 1;
SeekBar seekBar;
ImageView back,pause,next,notLikes;
TextView text_fixed,text_plus;
ConstraintLayout playing_screen;
AnimationDrawable animationDrawable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_playing_screen);
playing_screen = findViewById(R.id.playing_screen);
notLikes = findViewById(R.id.notLikes);
text_fixed = findViewById(R.id.text_fixed);
text_plus = findViewById(R.id.text_plus);
seekBar = findViewById(R.id.seekBar);
back = findViewById(R.id.back);
pause = findViewById(R.id.pause);
next = findViewById(R.id.next);
//setting of click listeners ofr buttons
notLikes.setOnClickListener(this);
seekBar.setOnClickListener(this);
back.setOnClickListener(this);
pause.setOnClickListener(this);
next.setOnClickListener(this);
StateListDrawable background = (StateListDrawable) playing_screen.getBackground();
Drawable current = background.getCurrent();
if(current instanceof AnimationDrawable){
animationDrawable =(AnimationDrawable) current;
animationDrawable.setEnterFadeDuration(5000);
animationDrawable.setExitFadeDuration(5000);
animationDrawable.start();
}
}
@Override
protected void onResume() {
super.onResume();
if(animationDrawable != null && animationDrawable.isRunning()){
animationDrawable.start();
}
}
Log Cat:
Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.StateListDrawable.getCurrent()' on a null object reference at com.musicapp.android.musicapp.PlayingScreen.onCreate(PlayingScreen.java:46) –
XML;
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PlayingScreen"
android:paddingBottom="25dp"
android:id="@+id/playing_screen">
I am having problems with my Animation drawable. It is telling me it's pointing to a null object reference, but i'm pretty sure that it isn't. How do I fix that?
Any help would be very helpful at this point! thank you!
Arun Abimanyu :
Try this below code
Drawable current=playing_screen.getBackground();
if (current instanceof AnimationDrawable) {
animationDrawable=current;
animationDrawable.setEnterFadeDuration(4000);
animationDrawable.setExitFadeDuration(4000);
animationDrawable.start();
}
}
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=341261&siteId=1