When you click on the button, it throws it out of the application. From 32 to 40 line. Namely:

Button btn = (Button) findViewById(R.id.button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Eng_lvl.this, Eng_learn.class); startActivity(intent); finish(); } });` package com.daylang.daylang; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageView; import java.util.Calendar; public class Eng_lvl extends AppCompatActivity { private int curTime; private int someValue; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loadscreen); Calendar calendar = Calendar.getInstance(); //noinspection WrongConstant if (calendar.get(Calendar.DATE) == 1) { setContentView(R.layout.eng_lvl); } else if (calendar.get(Calendar.DATE) == Calendar.WEDNESDAY) { setContentView(R.layout.eng_learn); } StartAnimations(); Button btn = (Button) findViewById(R.id.button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Eng_lvl.this, Eng_learn.class); startActivity(intent); finish(); } }); } private void StartAnimations() { Animation anim = AnimationUtils.loadAnimation(this, R.anim.mytrans); anim.reset(); ImageView iv = (ImageView) findViewById(R.id.stars); iv.clearAnimation(); iv.startAnimation(anim); anim = AnimationUtils.loadAnimation(this, R.anim.mytrans2); anim.reset(); ImageView l = (ImageView) findViewById(R.id.stars2); l.clearAnimation(); l.startAnimation(anim); anim = AnimationUtils.loadAnimation(this, R.anim.mytrans5); anim.reset(); ImageView B = (ImageView) findViewById(R.id.stars3); B.clearAnimation(); B.startAnimation(anim); } } 
  • Add error logs (including error type) and specify unambiguously on which line it falls. Most likely you have an NPE and there is simply no button with the specified ID in the markup, i.e. you just have a typo. - Yuriy SPb
  • Before replacing markup in activit, you need to know that all this will hardly work - pavlofff
  • calendar.get(Calendar.DATE) == Calendar.WEDNESDAY compare the number in the month with the Wednesday, the occupation is a bit strange. - eugeneek
  • @eugeneek is true ... I didn’t think about it, but if I write else if (calendar.get (Calendar.DATE) == 2) then the number 2 is underlined in red. - Seth Orton

1 answer 1

At a minimum, check for null, especially if it is not (Button).