Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 动画可绘制-空对象引用_Java_Android_Android Studio - Fatal编程技术网

Java 动画可绘制-空对象引用

Java 动画可绘制-空对象引用,java,android,android-studio,Java,Android,Android Studio,我的动画绘制有问题。它告诉我它指向一个空对象引用,但我很确定它不是。我该如何解决这个问题 在这一点上,任何帮助都会非常有用!谢谢大家! public class PlayingScreen extends AppCompatActivity implements View.OnClickListener { int notLike_Liked = 1; int Pause_Play = 1; SeekBar seekBar; ImageView back,pause,next,notLikes

我的动画绘制有问题。它告诉我它指向一个空对象引用,但我很确定它不是。我该如何解决这个问题

在这一点上,任何帮助都会非常有用!谢谢大家!

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();

    }
}
日志类别:

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


我的动画绘制有问题。它告诉我它指向一个空对象引用,但我很确定它不是。我该如何解决这个问题

在这一点上,任何帮助都会非常有用!谢谢大家!

试试下面的代码

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();

    }
}
 Drawable current=playing_screen.getBackground();
 if (current instanceof AnimationDrawable) {
  animationDrawable=current;
  animationDrawable.setEnterFadeDuration(4000);
  animationDrawable.setExitFadeDuration(4000);
  animationDrawable.start();
  }
}

. Drawable current=background.getCurrent();非常感谢。这很有帮助。但现在我发现了这个错误:尝试调用虚拟方法“android.graphics.drawable.drawable android.graphics.drawable.StateListDrawable.getCurrent()'在com.musicapp.android.musicapp.PlayingScreen.onCreate(PlayingScreen.java:46)上的空对象引用上,编辑回滚以恢复问题的相关代码,因为问题文本不再匹配错误消息谢谢!这很有帮助。但现在我发现了这个错误:尝试调用虚拟方法“android.graphics.drawable.drawable android.graphics.drawable.StateListDrawable.getCurrent()在com.musicapp.android.musicapp.PlayingScreen.onCreate(PlayingScreen.java:46)上的空对象引用上,您可以添加xml吗?这不会让meI添加少量xml。我正在尝试更改Constrail布局的背景色(它的id正在播放屏幕)