我試圖啓動我的應用程序,但我一直在運行時出現錯誤。 該程序的定義是:應用程序啓動時,用戶點擊按鈕,按鈕將不可見和倒計時完成後開始倒計時Menu.java將打開。Android在啓動應用程序時出現運行時錯誤
這裏是我下面的代碼:
Main.java
public class Main extends Activity {
TextView countDown;
int counter;
Intent menuIntent;
Button appStartButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
menuIntent = new Intent("com.example.project_21.MENU");
counter = 5;
countDown = (TextView) findViewById(R.id.countDown);
appStartButton = (Button) findViewById(R.id.appStartButton);
appStartButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.setVisibility(View.GONE);
while (counter != 0) {
sleep(1000);
counter--;
countDown.setText(counter + " seconds");
}
startActivity(menuIntent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void sleep(long mill) {
try {
Thread.sleep(mill);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
的Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project_21"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.project_21.Main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.project_21.Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.project_21.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/android2"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Main" >
<TextView
android:id="@+id/startsInfo"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:gravity="center"
android:text="@string/welcome"
android:textSize="30sp" />
<TextView
android:id="@+id/countDown"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/countDown"
android:textSize="45sp" />
<Button
android:id="@+id/appStartButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/appStartButton"
android:textSize="35sp" />
</LinearLayout>
錯誤日誌
什麼是錯誤?發佈堆棧跟蹤 –
@ Archie.bpgc我添加了錯誤日誌的圖片 –
您的錯誤所在的類不包括在內(這是Menu.java) – Booger