I'm having a bit of an issue with my android button. When I press it, my app crashes, and in my logcat, I have the following error:
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?
The weird thing is that the activity that I'm starting when I click my button isn't GameView, it's GameActivity (which uses GameView as its View). I didn't have the activity declared in my manifest before, so I did that, but I'm still getting the same error. This is how I set up my button:
@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;
}
}
And here is the button in my xml:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start"
android:id="@+id/start_button"
/>
Lastly, here is my GameActivity class:
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();
}
}
I know it's not an issue with my GameView because I tried using another view from another app which I know works. This is really frustrating because it's just an issue with my button. Any help would be greatly appreciated!