Android的 - 获得一个图像资源到乌里:抛出:IllegalArgumentException [英] Android - getting an image resource into Uri: IllegalArgumentException
问题描述
我试图加载从资源的图像在我的Android应用程序,但我不断收到:错误IllegalArgumentException的URI预期的文件格式
I'm trying to load an image from the resource in my Android app but I keep getting the "IllegalArgumentException: Expected file scheme in URI" error.
我把我的'missing_album_art.png文件中绘制,华电国际,绘制,LDPI,并在我的项目绘制,MDPI文件夹,并刷新Eclipse中,这样它会显示他们的存在。
I put my 'missing_album_art.png' file in drawable-hdpi, drawable-ldpi and drawable-mdpi folders in my project and refreshed Eclipse so that it displays they're there.
我使用创造了开放的线路是:
The line I'm using to create the Uri is:
Uri uri = Uri.parse("android.resource://android.aberplayer/R.drawable.missing_album_art");
在'android.aberplayer'是我的应用程序的主包,也包含在其中我使用上述行类的人。
The 'android.aberplayer' is the main package of my application and also the one containing the class in which I use the above line.
我不断收到的错误是:
03-16 00:16:29.252: E/AndroidRuntime(25598): FATAL EXCEPTION: main
03-16 00:16:29.252: E/AndroidRuntime(25598): java.lang.IllegalArgumentException: Expected file scheme in URI: android.resource://src.android.aberplayer/R.drawable.missing_album_art
03-16 00:16:29.252: E/AndroidRuntime(25598): at java.io.File.checkURI(File.java:245)
03-16 00:16:29.252: E/AndroidRuntime(25598): at java.io.File.<init>(File.java:182)
03-16 00:16:29.252: E/AndroidRuntime(25598): at android.aberplayer.CurrentSongList.getCurrentAlbumArt(CurrentSongList.java:69)
有什么我不明白有关访问图像资源的Android应用程序?
Is there something I don't understand about accessing the image resources in Android applications?
推荐答案
如果你可以把图像文件到资产
文件夹中,code以下,可使用获得乌里
-
If you can put the image file into assets
folder, the code below can be used to get the Uri
-
Uri uri=Uri.parse("file:///android_asset/images/missing_album_art.png");
注意 Uri.parse
被用于获取乌里
从字符串网址
不是从资源直接。还有其他更清洁的解决办法,但我不记得他们。当我发现他们,我会更新帖子。
Note that Uri.parse
is used for getting Uri
from a string Url
not from a resource directly. There are other cleaner solution, but I couldn't recall them. I'll update the post when I found them.
编辑: 该字符串URI路径应该是以下格式,如果您想直接使用资源: -
The String Uri path should be in the following format if you want to use the resource directly:-
"android.resource://[package]/[res type]/[res name]"
检查这一职务。
这篇关于Android的 - 获得一个图像资源到乌里:抛出:IllegalArgumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!