[英]MediaPlayer.create cannot be resolved to a type
我正在嘗試獲取一個mp3文件,以在單擊按鈕時播放聲音(Android應用程序)。 但是,盡管遵循了使用類似代碼的教程,但仍收到此錯誤消息“ MediaPlayer.create無法解析為類型。 我已經刷新了該項目並清理了該項目,但沒有任何影響。 這是我的代碼:
package com.example.h.a.t;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class Hypo_Info extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hypo_info);
final MediaPlayer mediaPlayer = new MediaPlayer.create(this, R.raw.pill_bottle);
Button a = (Button) findViewById(R.id.treatment_hypo);
a.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Hypo_Info.this, Hypo_Treatment.class);
startActivity(i);
mediaPlayer.start();
}
});
}
問題是這里的“ new”關鍵字:
new MediaPlayer.create(this, R.raw.pill_bottle);
因為MediaPlayer.create是靜態方法。
==>刪除new
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.