eclipse 我找不到 R.raw.xxx

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5741548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:12:51  来源:igfitidea点击:

I can't finde R.raw.xxx

androideclipse

提问by Zulummar

I found in the last couple of Days a lot of simular Questions but neither gave me a working answer so pls excuse me for asking again, but maybe someone can help me...

在过去的几天里,我发现了很多类似的问题,但都没有给我一个有效的答案,所以请原谅我再次提问,但也许有人可以帮助我......

Problem:
IDE: Eclipse 3.6.2;
Android SDK

问题:
IDE:Eclipse 3.6.2;
安卓SDK

In order to load an small mp3 to the res/raw i created the folder raw in res... and added the file in the raw folder with New > File... so far so good...

为了将一个小的 mp3 加载到 res/raw,我在 res... 中创建了 raw 文件夹,并使用 New > File... 添加了 raw 文件夹中的文件...

BUT:

但:

MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1);
    mp.start();

R.raw or any other way to get raw wont work.... and i can't get to the sound_file
if i look in class R.java it don't contains raw...
I really don't know what else i can do...
Maybe someone can help me please...
Thanks in advance

R.raw 或任何其他获取原始数据的方法都不起作用......
如果我查看 R.java 类中不包含原始数据的类,我将无法访问 sound_file ......
我真的不知道还有什么我可以做......
也许有人可以帮助我......
提前致谢

采纳答案by Jason Rogers

Thing you should be careful about :

你应该注意的事情:

1) that your file name doesn't contain any illigal caracters. if it does then it will fail to create the R file correctly and so you can't use R (the error message appears in the the regular eclipse console)

1) 您的文件名不包含任何非法字符。如果是,那么它将无法正确创建 R 文件,因此您无法使用 R(错误消息出现在常规 Eclipse 控制台中)

2) check that you have "loaded" your file to the project do ctrl (or cmd on mac)+shif+o on the root of your project in elcipse browser (reloads all resources) then F5 to refresh the files structures and the a clean project to force a nice clean build

2)检查您是否已将文件“加载”到项目中,在elcipse浏览器中的项目根目录上执行ctrl(或mac上的cmd)+ shif+o(重新加载所有资源),然后按F5刷新文件结构和a干净的项目来强制一个漂亮的干净构建

3) you could check if you have the RIght R files imported to your project, there is a default R file something like android.R instead of projectPackages.R

3)你可以检查你是否有正确的 R 文件导入到你的项目中,有一个默认的 R 文件,比如 android.R 而不是 projectPackages.R

hope this helps

希望这可以帮助

Jason

杰森

回答by Heiko Rupp

You need to rebuild/recreate R.java - that file is generated on demand.

您需要重建/重新创建 R.java - 该文件是按需生成的。

In Eclipse this may need a "clean & build" action. You may also refresh the project in the project view, it will repopulate all the assets and when you build, it will repopulate R.raw for you

在 Eclipse 中,这可能需要“清理和构建”操作。您也可以在项目视图中刷新项目,它会重新填充所有资产,当您构建时,它会为您重新填充 R.raw

In IntelliJ IDEA, you have a context menu option "Force generate R.java" when you stand on such a resource file.

在 IntelliJ IDEA 中,当您站在这样的资源文件上时,您有一个上下文菜单选项“强制生成 R.java”。

NOTEThe R file won't be re-generated if you have a compilation error in one of your Java/XML files

注意如果您的 Java/XML 文件之一出现编译错误,则不会重新生成 R 文件

回答by Imran Khan

If the file has an all-caps filename, rename the file to all lower case. (An error message might appear: "Invalid file name: must contain only [a-z0-9_.]") I wonder if it is related to the case preserving but case insensitive file system on a mac? (I'm developing on a Mac.)

如果文件的文件名全部大写,请将文件重命名为全部小写。(可能会出现一条错误消息:“无效的文件名:必须只包含 [a-z0-9_.]”)我想知道它是否与 mac 上的大小写保留但不区分大小写的文件系统有关?(我正在 Mac 上开发。)

回答by Guillermo Zooby

Be Careful, the same thing happened to me. Check your imports, I had a mistake and wrote

小心,同样的事情发生在我身上。检查您的导入,我有一个错误并写道

import android.R;

导入android.R;

Instead, I changed it for

相反,我改变了它

projectroot.mypackage.R;

projectroot.mypackage.R;

回答by Carlos

I had the same problem and I solved it. The fact was that the file names were in Capital Ex, Song1.mp3... I only renamed it song1.mp3and it works..

我有同样的问题,我解决了它。事实是文件名在Capital Ex, Song1.mp3... 我只重命名了它song1.mp3并且它有效..

回答by Frank Mehlhop

I renamed the music-file to only lower case letters and nothing else. Than it works (after long time researching).

我将音乐文件重命名为仅小写字母,仅此而已。比它有效(经过长时间的研究)。

回答by Rui

Windows Explorer checks the audio file, not Eclipse.

Windows 资源管理器检查音频文件,而不是 Eclipse。