1

I'm new at android programming and I have a problem about starting new activity from my another class and media player. My activity class has a media controller. I try to call the activity like this:

public void Collide(FlxCore object1, FlxCore object2) {
        player.kill();
        Context mContext = null;
        Intent myIntent = new Intent(mContext, soru.class);
        mContext.startActivity(myIntent);
    }

My activity is:

public class soru extends Activity {
    private VideoView mVideoView;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.soru);
        mVideoView = (VideoView) findViewById(R.id.surface_view);
        mVideoView.setVideoURI(Uri.parse("android.resource://"
                + getPackageName() + "/" + R.raw.arabaa));
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();
    }

}

Then the problem is

12-07 13:14:54.675: W/dalvikvm(526): threadid=9: thread exiting with uncaught exception (group=0x40015560)
12-07 13:14:54.675: E/AndroidRuntime(526): FATAL EXCEPTION: Thread-10
12-07 13:14:54.675: E/AndroidRuntime(526): java.lang.NullPointerException
12-07 13:14:54.675: E/AndroidRuntime(526):  at android.content.ComponentName.<init>(ComponentName.java:75)
12-07 13:14:54.675: E/AndroidRuntime(526):  at android.content.Intent.<init>(Intent.java:2702)
12-07 13:14:54.675: E/AndroidRuntime(526):  at org.myname.flixeldemo.GameState$3.Collide(GameState.java:101)
12-07 13:14:54.675: E/AndroidRuntime(526):  at org.flixel.FlxG.overlapArrayList(FlxG.java:456)
12-07 13:14:54.675: E/AndroidRuntime(526):  at org.myname.flixeldemo.GameState.update(GameState.java:95)
12-07 13:14:54.675: E/AndroidRuntime(526):  at org.flixel.FlxGame.onEnterFrame(FlxGame.java:327)
12-07 13:14:54.675: E/AndroidRuntime(526):  at org.flixel.FlxGameView$GameThread.run(FlxGameView.java:55)
12-07 13:14:54.815: E/MediaPlayer(526): pause called in state 64
12-07 13:14:54.815: E/MediaPlayer(526): error (-38, 0)
12-07 13:14:54.815: E/MediaPlayer(526): Error (-38,0)
12-07 13:19:54.830: I/Process(526): Sending signal. PID: 526 SIG: 9

I couldn't understand the what the problem really is and how can I fix it.Please help me.

mac
  • 42,153
  • 26
  • 121
  • 131
ylncn
  • 11
  • 1
  • you should take a look at this: http://source.android.com/source/code-style.html If you are following the conventions of android codestyle. Then it might be that you dont know how to use stackoverflow.. Please put your code in code brackets, it is utterly impossible to read your code as it is now. imho. – Anders Metnik Dec 07 '11 at 13:59

1 Answers1

0

This one isn't that hard to figure out.

Your error points to a NullPointerException, meaning you're trying to use an object that's either empty, or doesn't exist.

Taking a quick look through your code reveals the problem:

Collide(FlxCore object1, FlxCore object2) {
    player.kill();
    Context mContext = null; // <<- You're creating an empty context object
    Intent myIntent = new Intent(mContext, soru.class); // And then
    mContext.startActivity(myIntent); // Use it for multiple functions
}

You can't use empty objects like that. Try using this or (yourclassname).this instead of null.

Sander van't Veer
  • 5,930
  • 5
  • 35
  • 50
  • Thanks for your reply. But when i try to use this or (classname).this there is a mismatch with my class and context. My class isn't an activity it is only a class. Is there any other way calling activity in my class or fixing this problem? – ylncn Dec 07 '11 at 14:41
  • You can try sending the context to the helper class when creating it. Look at this thread for more info: http://stackoverflow.com/questions/5339941/android-how-to-use-getapplication-and-getapplicationcontext-from-non-activity or http://stackoverflow.com/questions/5498669/android-needing-context-is-non-activity-classes – Sander van't Veer Dec 07 '11 at 14:44
  • Depend on your suggestion, i fix the problem. The problem all my classes are non activity, but there is only one activity class. I get context from it then i can start my activity. – ylncn Dec 09 '11 at 21:55
  • So your problem is fixed now? – Sander van't Veer Dec 09 '11 at 21:56
  • Yes, the problem is fixed now. Thank you. – ylncn Dec 09 '11 at 22:04
  • Alright, you're welcome. Could you accept my answer as the correct one so this question get's removed from the `Unanswered` list? – Sander van't Veer Dec 09 '11 at 22:09