我使用了来自CODE的代码,我想使用drawables文件夹中的图片,但代码需要一个URL。
我试着这样做:
android.net.Uri aURI = Uri.parse("android.resource://com.kapsapetapp.kapsapet" + R.drawable.icon_bar);
try {
java.net.URI jURI = new java.net.URI(aURI.toString());
URL url = jURI.toURL();
imgLoader.DisplayImage(url.getPath(), loader, iconBar_View);
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
然而它没有加载图像。什么可以解决这个问题?
日志
04-20 13:23:04.176 2458-2458 / com.kapsapetapp.kapsapet W / System.err:java.net.MalformedURLException:未知协议:android.resource
04-20 13:23:04.176 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at java.net.URL。(URL.java:182)
04-20 13:23:04.176 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at java.net.URL。(URL.java:125)
04-20 13:23:04.176 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at java.net.URI.toURL(URI.java:1378)
04-20 13:23:04.176 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at com.kapsapetapp.kapsapet.FullscreenActivity.onCreate(FullscreenActivity.java:142)
04-20 13:23:04.176 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at android.app.Activity.performCreate(Activity.java:5937)
04-20 13:23:04.176 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
04-20 13:23:04.177 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
04-20 13:23:04.177 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
04-20 13:23:04.177 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at android.app.ActivityThread.access $ 800(ActivityThread.java:144)
04-20 13:23:04.177 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1278)
04-20 13:23:04.177 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at android.os.Handler.dispatchMessage(Handler.java:102)
04-20 13:23:04.177 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at android.os.Looper.loop(Looper.java:135)
04-20 13:23:04.177 2458-2458 / com.kapsapetapp.kapsapet W / System.err:在android.app.ActivityThread.main(ActivityThread.java:5221)
04-20 13:23:04.177 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at java.lang.reflect.Method.invoke(Native Method)
04-20 13:23:04.177 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at java.lang.reflect.Method.invoke(Method.java:372)
04-20 13:23:04.178 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)<< >
04-20 13:23:04.178 2458-2458 / com.kapsapetapp.kapsapet W / System.err:at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
答案 0 :(得分:0)
要从drawables显示图像,无需使用java.net.URI
。这样做:
Uri uriImage = Uri.parse("drawable://" + R.drawable.icon_bar);
imgLoader.DisplayImage(String.valueOf(uriImage), loader, iconBar_View);