gpt4 book ai didi

android - 如何从 Assets 中加载所有图像?

转载 作者:行者123 更新时间:2023-11-29 01:29:25 25 4
gpt4 key购买 nike

我尝试从 assets 文件夹加载图像,但出现 FileNotFoundException

我使用了两种方法:

try {
AssetManager am = MainActivity.this.getAssets();
String[] files = am.list("cards");
InputStream istr = null;
for (String file : files) {
Log.d("MyLogs", file);
istr = am.open(file);
Drawable d = Drawable.createFromStream(istr, null);
drawables.add(d);
}
} catch (IOException e) {
e.printStackTrace();
}

并使用Bitmap....同样的问题....日志:

08-19 18:51:17.043    5246-5246/com.example.admin.background D/MyLogs﹕ ic_credit_card_black_48dp.png
08-19 18:51:17.043 5246-5246/com.example.admin.background W/System.err﹕ java.io.FileNotFoundException: ic_credit_card_black_48dp.png
08-19 18:51:17.111 5246-5246/com.example.admin.background W/System.err﹕ at android.content.res.AssetManager.openAsset(Native Method)
08-19 18:51:17.111 5246-5246/com.example.admin.background W/System.err﹕ at android.content.res.AssetManager.open(AssetManager.java:315)
08-19 18:51:17.115 5246-5246/com.example.admin.background W/System.err﹕ at android.content.res.AssetManager.open(AssetManager.java:289)
08-19 18:51:17.115 5246-5246/com.example.admin.background W/System.err﹕ at com.example.admin.background.MainActivity.onCreate(MainActivity.java:58)
08-19 18:51:17.119 5246-5246/com.example.admin.background W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5104)
08-19 18:51:17.119 5246-5246/com.example.admin.background W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-19 18:51:17.119 5246-5246/com.example.admin.background W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-19 18:51:17.119 5246-5246/com.example.admin.background W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-19 18:51:17.119 5246-5246/com.example.admin.background W/System.err﹕ at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-19 18:51:17.119 5246-5246/com.example.admin.background W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-19 18:51:17.119 5246-5246/com.example.admin.background W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 18:51:17.119 5246-5246/com.example.admin.background W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
08-19 18:51:17.123 5246-5246/com.example.admin.background W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5041)
08-19 18:51:17.123 5246-5246/com.example.admin.background W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
08-19 18:51:17.123 5246-5246/com.example.admin.background W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
08-19 18:51:17.123 5246-5246/com.example.admin.background W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-19 18:51:17.123 5246-5246/com.example.admin.background W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-19 18:51:17.123 5246-5246/com.example.admin.background W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)

最佳答案

您忘记包含您的文件夹。这应该有效:

istr = am.open( "cards/" + file );

关于android - 如何从 Assets 中加载所有图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32103710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com