Monday, April 30, 2012

Re: [android-developers] public variables

(Bearing in mind the warning you were giving [by another member] about
globals being evil, don't make *everything* static.)

>public static Context context;
>public static MediaPlayer mp=MediaPlayer.create(context, R.drawable.klik);

Your error is probably that you declared an object called 'context' but
didn't assign anything to it (it remains null) - an Activity is itself a
Context, so 'this' is the usual way, I believe, but it needs to be in the

public class play extends Activity{

public static MediaPlayer mp= null ;

public play()
if (mp == null) // The singleton instance not yet created.
mp = MediaPlayer.create(this, R.drawable.klik);


You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment