Answer the question
In order to leave comments, you need to log in
Java Android: error in code. How to fix?
Code:
package ua.dominqnta.dubstepgun;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
int track = 0;
MediaPlayer mediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button switch_t = (Button) findViewById(R.id.button1);
OnClickListener oclswitch = new OnClickListener(){
@SuppressWarnings("deprecation")
@SuppressLint("CutPasteId")
@Override
public void onClick(View arg0) {
track++;
if(track==1)
{
mediaPlayer = MediaPlayer.create(this, R.raw.industrial);
}
if(track==2)
{
mediaPlayer = MediaPlayer.create(this, R.raw.one);
}
if(track==3)
{
mediaPlayer = MediaPlayer.create(this, R.raw.meet_the_presedent);
}
if(track==4)
{
mediaPlayer = MediaPlayer.create(this, R.raw.four);
}
if(track==5)
{
mediaPlayer = MediaPlayer.create(this, R.raw.five);
}
}
};
switch_t.setOnClickListener(oclswitch);
}
}
Error in mediaPlayer = MediaPlayer.create(this, R.raw.one); : The method create(Context, int) in the type MediaPlayer is not applicable for the arguments (new View.OnClickListener(){}, int)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question