媒体播放器没有按规定R.raw - Android电子 [英] mediaplayer failing on R.raw - Android
问题描述
导入进口android.media.MediaPlayer
,有人告诉我原料不能被解析
在
private void playSound(){
MediaPlayer mp = MediaPlayer.create(this, R.raw.Jam);
...
我是真正的新的Android
,什么是原材料
的呢?我怎么能解决这个问题?
I am really new to Android
, what is raw
for ? and how can I fix this problem ?
推荐答案
一个原始文件夹包含任何类型的文件。你需要一个原材料
文件夹下的资源文件夹( RES
)。在你的榜样,果酱
有望作为原材料
文件夹中的资源,将可能是一个类型的音乐文件因为你使用的MediaPlayer
尝试阅读。
A raw folder holds files of any type. You need a raw
folder under your resources folder (res
). In your example, jam
is expected as a resource in the raw
folder, and will likely be a type of music file as you're using MediaPlayer
to try and read it.
您已经这个错误原料不能被解析
,因为原始文件夹不存在,所以变量原材料
类研究
是不是自动生成的。
You've this error raw cannot be resolved
because raw folder doesn't exist, and so the variable raw
in class R
is not being auto-generated.
通过创建原材料
文件夹修复的问题。
Fix the problem by creating the raw
folder.
如果您已经创建 RES /原料
尝试清洗项目。有时候Eclipse的迷糊。如果不工作,做一个小的变化到一个源文件,并保存它,以便自动生成过程中揭开序幕。有时手动清洗也没有固定的问题对我来说,为Eclipse的一个已知的bug。
If you already have created res/raw
try cleaning the project. Sometimes Eclipse gets confused. If that doesn't work, make a small change to a source file, and save it so the auto-build process kicks off. Sometimes cleaning manually hasn't fixed the problem for me, its a known bug for Eclipse.
这篇关于媒体播放器没有按规定R.raw - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!