Android Raw 文件夹 - 创建和参考

发布于 2024-11-03 08:28:18 字数 234 浏览 1 评论 0原文

我正在尝试为我的 Android 应用程序创建一个原始文件夹,其中将保存不同的媒体文件以供稍后使用。但我似乎无法在 .java 类中引用创建的原始文件夹。

例如:R.? ->这将返回我可以使用的所有可能资源的列表,例如基本的可绘制、布局和值文件夹。但是它不会显示原始文件夹。

说 raw 被创建为通用文件夹而不是其他文件夹是否正确?或者是否必须在 AndroidManifest.xml 文件中声明才能被识别为资源?

I'm trying to create a raw folder for my android app which will hold different media files for use later. But I can't seem to be able to reference the created raw folder in my .java classes.

For example: R.? -> This returns a list of all possible resources I can use like the basic drawable, layout and values folder. However it won't display the raw folder.

Is it correct to say that raw is created as a general folder and nothing else? Or does it have to be declared in the AndroidManifest.xml file in order to be recognised as a resource?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

李不 2024-11-10 08:28:18

raw文件夹必须位于res文件夹内,否则无法工作。

The raw folder must be inside the res folder, otherwise it won't work.

青巷忧颜 2024-11-10 08:28:18

右键单击,在弹出窗口中单击新建,然后单击 android 资源目录
将出现一个新窗口,将资源类型更改为原始副本,将过去的歌曲更改为原始文件夹
记住不要将歌曲文件拖放到原始文件夹中,并且歌曲拼写应为小写此方法适用于 Android Studio 链接
在此处输入图像描述

Right click on package click on new on popup then click on android resource directory
a new window will be appear change the resource type to raw copy and past song to raw folder
remember don't drag and drop song file to raw folder and song spell should be in lower case This method is for Android Studio Link
enter image description here

萌酱 2024-11-10 08:28:18

如果您创建并放入一些文件到常规文件夹中,则会出现错误。
将一些媒体文件放入 raw 文件夹中,然后您可以将 raw 文件夹引用到您的 .java 文件中。

希望它能消除您所有的疑虑。

General folder will get error if you create and put some file into it.
Put some media file into raw folder then you can able to refer the raw folder into your .java files.

Hope it will clear all your doubts.

墨洒年华 2024-11-10 08:28:18

只需在“res”文件夹中创建“raw”并将媒体文件放入该 raw 文件夹中即可。
然后尝试通过您的程序访问该媒体文件,例如
R.raw.mediaFile

Just create 'raw' inside 'res' folder and place media file inside that raw folder.
Then try to access that media file through your program like
R.raw.mediaFile

夏见 2024-11-10 08:28:18

当我第一次在 res 中创建 raw 文件夹时,我无法使用 R.raw 访问它,但我仍然使用 R.raw.music< /code> 在我的代码中[显示无法引用此文件夹的错误],并且当部署该错误消失的应用程序时,我的应用程序运行没有任何问题。之后,我可以使用 R.raw 访问 raw 文件夹。

When I created raw folder inside res for the first time, I was not able to access it using R.raw but still I use R.raw.music in my code [showing me error that can not reference to this folder] and when deploy the app that error gone away, my app run without any problem. After that, I was able to access raw folder using R.raw.

岁吢 2024-11-10 08:28:18

在 Android 中,北极狐

点击应用程序右键 ->新->文件夹->原始资源文件夹

在此输入图像描述

In Android Arctic Fox

Click right on App -> New -> Folder -> Raw Resources Folder

enter image description here

ぺ禁宫浮华殁 2024-11-10 08:28:18

您还需要遵循命名约定,同时将任何媒体文件放入原始文件夹中。就我而言,我的文件名不正确,并且还提示我无法找到 R 文件的错误。但正如 @Kesha 所说,它构建成功,同时也提示我一个错误

You also need to follow the naming convention while putting any media file in raw folder as well. In my case my file name was not correct and it was also prompting me an error that unable to find R file. But as @Kesha said it build successfully while it was prompting me an error as well

苏璃陌 2024-11-10 08:28:18

Stack Overflow 上的另一个答案对此有所帮助。您只需转到“构建”>“清理项目,这将自动解决您的问题。

Another answer on Stack Overflow helped with this. You can just go to Build > Clean Project and that will automatically resolve your issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文