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
constructor):

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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment