在我的應用程序專注於獲取隨機名稱時,我調試它通過USB調試它時真的令人困惑的問題。當啓動屏幕時間結束時,出現Android系統通信,其中顯示「很遺憾,」yourapp'已停止「。我不知道發生了什麼,因爲一切都很好,並且沒有顯示錯誤。這裏是我的代碼:我的簡單應用程序崩潰,我不知道爲什麼
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]);
}
}
請提供您的logcat –
能否請你把錯誤信息從Android的顯示器? – Jeffy
我猜這是類似於[將變量放在類頂部的頂部](https://stackoverflow.com/a/18881067/1380752),但是您需要發佈堆棧跟蹤來確保。 – codeMagic