当我在倒计时3秒后发起另一项活动时,应用程序崩溃了

时间:2018-01-05 04:09:12

标签: java android parsing crash

这是我的MainActivity.java

  

公共类MainActivity扩展了AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate (savedInstanceState);
    setContentView (R.layout.activity_main2);
    CountDownTimer countDownTimer = new CountDownTimer (3000,1000) {
        @Override
        public void onTick(long l) {

        }

        @Override
        public void onFinish() {
            startActivity (new Intent (MainActivity.this, Main2Activity.class));
        }
    }.start ();
} }

这是我的Main2Activity.java

  

公共类Main2Activity扩展了AppCompatActivity {

public static Button button;
public static TextView temp;
public static TextView cityname;
public static TextView time;
public static EditText written;
public static ImageView imageView;
RelativeLayout relativeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate (savedInstanceState);
    setContentView (R.layout.activity_main);
    button = (Button) findViewById (R.id.button);
    temp = (TextView) findViewById (R.id.temp);
    cityname = (TextView) findViewById (R.id.cityname);
    time = (TextView) findViewById (R.id.time);
    relativeLayout = (RelativeLayout) findViewById (R.id.relative);
    written = (EditText) findViewById (R.id.editText);
    imageView = (ImageView) findViewById (R.id.imageView);
    button.setOnClickListener (new View.OnClickListener () {
        @Override
        public void onClick(View view) {
            try {
                if(written.getText ().toString ().isEmpty () || written.getText ().toString ().equals ("")){
                    Toast.makeText (Main2Activity.this, "Enter your City name", Toast.LENGTH_LONG).show ();
                }else {
                    time.setAlpha (0f);
                    temp.setAlpha (0f);
                    cityname.setAlpha (0f);
                    Parsing parsing = new Parsing ();
                    parsing.execute ();
                    written.setText("");
                }
            }catch (Exception e){

            }
        }
    });
} }

当我按下按钮时,此应用程序崩溃,没有任何应用程序崩溃。

0 个答案:

没有答案