当应用程序启动时我尝试立即旋转屏幕它给了我这个错误:
public void onDestroy() {
super.onDestroy();
appbars.animate().translationY(0).alpha(1).setDuration(100).setInterpolator(new DecelerateInterpolator());
}
错误:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewPropertyAnimator
android.support.design.widget.AppBarLayout.animate()' on a null object
reference
答案 0 :(得分:1)
尝试检查您的appbars
是否为null
public void onDestroy() {
super.onDestroy();
if(appbars!=null) {
appbars.animate().translationY(0).alpha(1).setDuration(100).setInterpolator(new DecelerateInterpolator());
}
答案 1 :(得分:1)
public void onDestroy() {
super.onDestroy();
if(appbars!=null){ // use this
appbars.animate().translationY(0).alpha(1).setDuration(100).setInterpolator(new DecelerateInterpolator());
}
答案 2 :(得分:1)
答案 3 :(得分:1)
试试这个..
public void onDestroy() {
super.onDestroy();
if(appbars!=null) {
appbars.animate().translationY(0).alpha(1).setDuration(100).setInterpolator(new DecelerateInterpolator());
}
}
希望这会有所帮助..