Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android MediaPlayer中的原始问题_Java_Android - Fatal编程技术网

Java android MediaPlayer中的原始问题

Java android MediaPlayer中的原始问题,java,android,Java,Android,我对按钮的声音有意见。即使我在“res”文件夹(res/raw)中创建文件夹,也不能使用“raw”。Eclipse问我是否要在R文件中创建它…它方便吗??请帮忙。任何帮助都是适当的 这个想法是当我点击一个ImageButton时,我会听到图像的颜色 MediaPlayer mp1 = MediaPlayer.create(this, R.raw.sound1); public void dos(View v) { TextView f = (TextView) findViewB

我对按钮的声音有意见。即使我在“res”文件夹(res/raw)中创建文件夹,也不能使用“raw”。Eclipse问我是否要在R文件中创建它…它方便吗??请帮忙。任何帮助都是适当的

这个想法是当我点击一个ImageButton时,我会听到图像的颜色

  MediaPlayer mp1 = MediaPlayer.create(this, R.raw.sound1);
  public void dos(View v) {
    TextView f = (TextView) findViewById(R.id.pts);
    TextView t = (TextView) findViewById(R.id.color);
    c++;
    if (t.getText().toString().equals("YELLOW")) {
        Toast.makeText(this, "Correct", Toast.LENGTH_SHORT).show();
        pts++;
        color(v);
        mp1.start();
        f.setText(Integer.toString(pts));
    } else {
        Toast.makeText(this, "Fail", Toast.LENGTH_SHORT)
                .show();

    }
}
唯一的问题是在这方面

MediaPlayer mp1 = MediaPlayer.create(this, R.raw.sound1);
raw带下划线,表示需要在R文件中创建字段或常量。

尝试更改:

MediaPlayer mp1 = MediaPlayer.create(this, R.raw.sound1);
为此:

`final MediaPlayer mp1 = MediaPlayer.create(this, R.raw.sound1);`

是否导入了正确的资源类?应该是.R