如何将assets文件夹中的URI的URI添加到MainActivity中?我的项目结构如下[重复]

问题描述 投票:-5回答:1

这个问题在这里已有答案:

  String url = "file:///app/src/main/assets/sample.jpg";

错误

W/System.err: java.io.FileNotFoundException: /app/src/main/assets/sample.jpg: open failed: ENOENT (No such file or directory)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:491)
W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:76)
W/System.err:     at org.apache.http.entity.mime.content.FileBody.writeTo(FileBody.java:100)
W/System.err:     at org.apache.http.entity.mime.HttpMultipart.doWriteTo(HttpMultipart.java:206)
W/System.err:     at org.apache.http.entity.mime.HttpMultipart.writeTo(HttpMultipart.java:224)
W/System.err:     at org.apache.http.entity.mime.MultipartEntity.writeTo(MultipartEntity.java:183)

enter image description here

java android
1个回答
1
投票

如果要从资源文件夹加载图像,可以使用资产管理器加载它

AssetManager assetManager = getAssets();
InputStream is = assetManager.open("sample.jpg");
Bitmap  bitmap = BitmapFactory.decodeStream(is);
imageView.setImageBitmap(bitmap);  

有关更多详细信息,请查看以下链接https://www.concretepage.com/android/android-assetmanager-example-to-load-image-from-assets-folder

我希望它会帮助你,还有一件事你也把你的.properties文件放在java文件夹中,这个类也是不正确的。所以也要纠正它。如有任何问题,请再次询问。

谢谢

© www.soinside.com 2019 - 2024. All rights reserved.