jeudi 24 août 2017

My simple app crashes and I do not know why

In my app focused on getting random names I am having really confusing problem while debugging it trough USB. When splash screen time ends, Android system communicate appears which says "Unfortunately, 'yourapp' has stopped". I do not know what is going on, because everything seems fine and there is no errors displayed. Here is my code:

public class MainActivity extends AppCompatActivity {

    private static int SPLASH_TIME_OUT = 4000;

    TextView mauncher;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mauncher = (TextView) findViewById(R.id.textView1);
        Typeface typeface0 = Typeface.createFromAsset(getAssets(), "Baloo-Regular.ttf");
        mauncher.setTypeface(typeface0);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent welcomeintent = new Intent(MainActivity.this, CitationActivity.class);
                startActivity(welcomeintent);
                finish();
            }
        },SPLASH_TIME_OUT);
    }

}


import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class CitationActivity extends AppCompatActivity {

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_citation);
       Intent welcomeintent = getIntent();
    }
    TextView textOne = (TextView) findViewById(R.id.textView2);
    String [] Names = {"Johnny", "Dominic", "Pablo", "Peter", "Frank"};
    public void sayHello (View view) {
        int rando = (int) (Math.random() * 5);
        textOne.setText(Names[rando]);
    }
}




Aucun commentaire:

Enregistrer un commentaire