I get this error**"java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setAnimation(android.view.animation.Animation)' on a null object reference"****
public class MainActivity extends AppCompatActivity {
private static int SPLASH_SCREEN = 5000;
Animation topAnim,bottomAnim;
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
topAnim = AnimationUtils.loadAnimation(this, R.anim.top_animation);
bottomAnim = AnimationUtils.loadAnimation(this, R.anim.bottom_animation);
ImageView Logo = findViewById(R.id.Logo);
TextView slogan = findViewById(R.id.slogan);
image.setAnimation(topAnim);
slogan.setAnimation(bottomAnim);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(MainActivity.this,Dashboard.class);
startActivity(intent);
finish();
}
},SPLASH_SCREEN);
}
}
You didn't matching image with your xml
image = findViewById(R.id.Logo);
instead of
ImageView Logo = findViewById(R.id.Logo);