I've studied from another app I coded in class which uses the Intent
to change to another class and layout and I thought the code was similar to what I have below. As it is, when I tap the 'New Game' button it simply crashes. I played around with commenting out the .stop
and .release
functions of my MediaPlayer
and I did notice it kills the music before it tries to get into the Intent
(then crashes). I'd appreciate any help, I've spent a few days trying to dig through forums :)
MainActivity.java:
public class MainActivity extends Activity {
private MediaPlayer mpTheme;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mpTheme=MediaPlayer.create(MainActivity.this, R.raw.sttngtheme);
mpTheme.start();
Button newGameButton = (Button) findViewById(R.id.newGameButton);
Button loadGameButton = (Button) findViewById(R.id.loadGameButton);
Button instructionsButton = (Button) findViewById(R.id.instructionsButton);
final MainActivity mainActivity = this;
newGameButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mpTheme.stop();
mpTheme.release();
//Toast.makeText(getBaseContext(), "You clicked New Game", Toast.LENGTH_LONG).show();
Intent startGameIntent = new Intent(mainActivity, Game.class);
startActivity(startGameIntent);
}
});
loadGameButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "Loading capability not yet coded.", Toast.LENGTH_LONG).show();
}
});
instructionsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "Instructions not yet coded.", Toast.LENGTH_LONG).show();
}
});
}//end onCreate
@Override
protected void onPause(){
super.onPause();
if(mpTheme.isPlaying()){
mpTheme.pause();
}
}
@Override
protected void onStop(){
super.onStop();
if(mpTheme.isPlaying()){
mpTheme.stop();
mpTheme.release();
}
}
@Override
protected void onResume(){
super.onResume();
if(mpTheme.isPlaying()==false){
mpTheme.start();
}
}
}
Game.java:
public class Game extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.quadrantspace);
}
}
Logcat:
12-10 21:09:19.978: D/AndroidRuntime(9184): Shutting down VM
12-10 21:09:19.980: E/AndroidRuntime(9184): FATAL EXCEPTION: main
12-10 21:09:19.980: E/AndroidRuntime(9184): Process: com.ferriss.superstartrek, PID: 9184
12-10 21:09:19.980: E/AndroidRuntime(9184): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.ferriss.superstartrek/com.ferriss.superstartrek.Game}; have you declared this activity in your AndroidManifest.xml?
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1868)
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1568)
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.app.Activity.startActivityForResult(Activity.java:3755)
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.app.Activity.startActivityForResult(Activity.java:3716)
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.app.Activity.startActivity(Activity.java:4036)
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.app.Activity.startActivity(Activity.java:3998)
12-10 21:09:19.980: E/AndroidRuntime(9184): at com.ferriss.superstartrek.MainActivity$1.onClick(MainActivity.java:34)
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.view.View.performClick(View.java:4785)
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.view.View$PerformClick.run(View.java:19884)
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.os.Handler.handleCallback(Handler.java:746)
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.os.Handler.dispatchMessage(Handler.java:95)
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.os.Looper.loop(Looper.java:135)
12-10 21:09:19.980: E/AndroidRuntime(9184): at android.app.ActivityThread.main(ActivityThread.java:5356)
12-10 21:09:19.980: E/AndroidRuntime(9184): at java.lang.reflect.Method.invoke(Native Method)
12-10 21:09:19.980: E/AndroidRuntime(9184): at java.lang.reflect.Method.invoke(Method.java:372)
12-10 21:09:19.980: E/AndroidRuntime(9184): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
12-10 21:09:19.980: E/AndroidRuntime(9184): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
12-10 21:09:21.509: I/Process(9184): Sending signal. PID: 9184 SIG: 9