Reputation: 93
So i get an error for this piece of code.
MediaPlayer mp = MediaPlayer.create(this, R.raw.whippingsound);
An the errors for this line (Eclipse Ide) is:
The method create(Context, int) in the type MediaPlayer is not applicable for the arguments (new View.OnClickListener(){}, int)
Now what am i missing in the parenthesis and can you explain to me what it is? Thanks! Whippingsound is my audio and raw is the folder. Thanks Guys!
Upvotes: 2
Views: 81
Reputation: 137282
Seems like you are creating the MediaPlayer in some listener, which is an internal (anonnymous) class, which its "this" hides the Activity this
. You need to give the fully qualified "this" as an argument, assuming your activity is called MyActivity, it should be:
MediaPlayer mp = MediaPlayer.create(MyActivity.this, R.raw.whippingsound);
Upvotes: 4
Reputation: 6536
The first argument to create, namely this
, is not a descendent of the class Context, so you cannot pass it to the create method.
Upvotes: 3