我有這樣的代碼:Drawable.createFromPath(文件路徑)返回null雖然文件中存在
String filePath = getActivity().getFileStreamPath("into11.png").getAbsolutePath();
if(Drawable.createFromPath(filePath)!=null){
img.setImageDrawable(Drawable.createFromPath(filePath));
}
else{
Log.d("nulllllllllllllllllllllllllllllllll","yessssssssssssssssssssssssssss");
}
文件路徑爲獲得圖像的正確道路「數據/數據/.../ intro11.png」但Drawable.createFromPath(filePath)爲null,所以這是什麼原因?
你的文件位於哪裏...? – Piyush
它在res中的可繪製文件夾中,其路徑爲/data/data/packagename/files/into11.png – User
嘗試使用URI代替:Uri uri = Uri.fromFile(filePath); \t \t img.setImageURI(uri); –