I want to display an image that is in my internal storage but I keep getting an error that "there is no such file of directory". I don't know what to set as the path to the file.
我想显示我的内部存储中的图像,但我不断收到“没有这样的目录文件”的错误。我不知道该设置什么作为文件的路径。
This is what I have:
这就是我所拥有的:
pButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View view) {
pBox.setImageBitmap(BitmapFactory.decodeFile("/internalstorage/pictures/cat.jpg"));
}
1 个解决方案
#1
Your path is not correct get storage path through this code and then add your picture path with this.
您的路径不正确通过此代码获取存储路径,然后添加您的图片路径。
File extStore = Environment.getExternalStorageDirectory();
String path = extStore.getPath() + "/pictures/cat.jpg"
Then use this path in
然后使用此路径
pBox.setImageBitmap(BitmapFactory.decodeFile(path));
Hope this will solve your solution.
希望这将解决您的解决方案。
#1
Your path is not correct get storage path through this code and then add your picture path with this.
您的路径不正确通过此代码获取存储路径,然后添加您的图片路径。
File extStore = Environment.getExternalStorageDirectory();
String path = extStore.getPath() + "/pictures/cat.jpg"
Then use this path in
然后使用此路径
pBox.setImageBitmap(BitmapFactory.decodeFile(path));
Hope this will solve your solution.
希望这将解决您的解决方案。