The Error i get is
cannot resolve method create(anonymous android.widget.AdapterView.OnItemClickListener, int)'
I Underlined the code
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, socialArrayPhrases);
socialPhrases.setAdapter(arrayAdapter);
socialPhrases.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position_of_phrase, long ld) {
Toast.makeText(getApplicationContext(),socialArrayPhrases.get(position_of_phrase) ,Toast.LENGTH_SHORT).show();
if(position_of_phrase == 0)
{
mediaPlayer = MediaPlayer.create(this, R.raw.test_audio);
-----------------------------------------------------------
}
}
});
Use encapsulating class name with this
.
mediaPlayer = MediaPlayer.create(EncapulatingClassWithContext.this, R.raw.test_audio);
Could be a Fragment
or an Activity
.
Make sure your first parameter is of type, It is expected to be context. You might be passing of type of adapter or fragment.
mediaPlayer = MediaPlayer.create(this, R.raw.test_audio); //This is not type of context
To quickly validate replace null with this and see
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.