user1148715
user1148715

Reputation: 93

What is supposed to be in this line? (java)

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

Answers (2)

MByD
MByD

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

Dhaivat Pandya
Dhaivat Pandya

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

Related Questions