[英]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.