Having troubles passing an intent

Put your problem here if it does not fit any of the other categories.

Having troubles passing an intent

Postby nin2246 » Fri Mar 02, 2012 8:37 pm

This is my main page java file press New game then go to New game menu and create character. Only it force closes after pressing button.

Code: Select all
package myPetRock.Jakob.Hindman;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

public class MyLittlePetRockActivity extends Activity implements
      OnClickListener {
   private static final String TAG = null;

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      // Creates onClickListener
      View new_button = findViewById(R.id.new_button);
      new_button.setOnClickListener(this);

      View continue_game = findViewById(R.id.continue_game);
      continue_game.setOnClickListener(this);

   }

   public void onClick(View v) {
      // TODO Auto-generated method stub

      // Case switch statement for main menu buttons
      switch (v.getId()) {
      case R.id.new_button:
         startGame(0);
         break;
      case R.id.continue_game:
         openSaveFile();
         break;
      }
   }

   public void openSaveFile() {
      // TODO Auto-generated method stub

      // Will open up a saved file on the SD card
   }

   public void startGame(int i) {
      Log.d(TAG, "clicked on " + i);
      // Start game here...
      Intent intent = new Intent(MyLittlePetRockActivity.this, Game.class);
      // intent.putExtra(Game.start_game, i);
      startActivity(intent);
   }
}
nin2246
Developer
Developer
 
Posts: 42
Joined: Wed Jan 18, 2012 8:08 pm

Top

Re: Having troubles passing an intent

Postby Phyll » Sat Mar 03, 2012 12:04 am

Hi nin2246,

I could take a wild guess since you aren't showing us any error codes or what your manifest looks like. But my first thought is that you don't have that activity called out in your manifest. If you do and it is indeed an activity that has a create, etc. then it should start. Without seeing what the error is, it could be starting and the intent is being sent perfectly but the Game class is crashing. Probably some other things.

Please show us some error codes or more code or something. Help us help you.

Thanks,

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Having troubles passing an intent

Postby nin2246 » Mon Mar 05, 2012 7:01 pm

Console
Code: Select all
[2012-03-05 11:57:49 - My Little Pet Rock] Starting activity myPetRock.Jakob.Hindman.MyLittlePetRockActivity on device emulator-5554
[2012-03-05 11:57:52 - My Little Pet Rock] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=myPetRock.Jakob.Hindman/.MyLittlePetRockActivity }


Log cat
Code: Select all
03-05 11:58:47.943: E/AndroidRuntime(916):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-05 11:58:47.943: E/AndroidRuntime(916):    at dalvik.system.NativeStart.main(Native Method)
03-05 11:58:47.943: E/AndroidRuntime(916): Caused by: java.lang.ClassCastException: myPetRock.Jakob.Hindman.Game cannot be cast to android.app.Activity
03-05 11:58:47.943: E/AndroidRuntime(916):    at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
03-05 11:58:47.943: E/AndroidRuntime(916):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
03-05 11:58:47.943: E/AndroidRuntime(916):    ... 11 more
03-05 11:58:50.101: I/Process(916): Sending signal. PID: 916 SIG: 9

nin2246
Developer
Developer
 
Posts: 42
Joined: Wed Jan 18, 2012 8:08 pm

Re: Having troubles passing an intent

Postby Phyll » Mon Mar 05, 2012 10:14 pm

Hi nin,

Well, this appears to be the error:

03-05 11:58:47.943: E/AndroidRuntime(916): Caused by: java.lang.ClassCastException: myPetRock.Jakob.Hindman.Game cannot be cast to android.app.Activity

I haven't seen this code yet (myPetRock.Jakob.Hindman.Game), but the error suggests that it is not a class that is extended from Activity or something that can be cast as an Activity. Is it in the manifest as an activity? It would appear that the intent is getting to its destination but Game cannot start.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Having troubles passing an intent

Postby nuetronprotron » Tue Mar 06, 2012 5:29 am

Hi nin,
as the error suggesting may be the Game class has not extended the Activity class and may be you have mentioned it as activity in you manifest file.I think may be these are the reasons i could think of.
nuetronprotron
Developer
Developer
 
Posts: 37
Joined: Tue Jan 10, 2012 10:22 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 23 guests