我遇到了一些與我的android按鈕有關的問題。當我按下它,我的應用程序崩潰,並且在我的logcat,我有以下錯誤:Android按鈕無法啓動活動
Caused by android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.defendthecastle/com.example.defendthecastle.GameView}; have you declared this activity in your AndroidManifest.xml?
奇怪的是,那我開始當我點擊我的按鈕,該活動並非GameView,它的GameActivity(使用GameView作爲其視圖)。我之前沒有在清單中聲明的活動,所以我這樣做了,但我仍然得到相同的錯誤。 這是我建立了我的按鈕:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View startButton = findViewById(R.id.start_button);
startButton.setOnClickListener(this);
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.start_button:
Intent i = new Intent(this, GameActivity.class);
startActivity(i);
break;
}
}
這裏是我的XML按鈕:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start"
android:id="@+id/start_button"
/>
最後,這裏是我的GameActivity類:
package com.example.defendthecastle;
import android.app.Activity;
import android.os.Bundle;
public class GameActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GameView gameView = new GameView(this);
setContentView(gameView);
gameView.requestFocus();
}
}
我知道這不是我的GameView的問題,因爲我嘗試使用另一個我認識的應用程序中的另一個視圖。這真是令人沮喪,因爲這只是我的按鈕的問題。任何幫助將不勝感激!
發佈您的清單 –
顯示您的清單 –
您在這裏的第一堂課是什麼? 'MainActivity'?顯示Manifest以及GameView類。目前還不清楚爲什麼系統認爲你試圖開始這種觀點作爲活動 –