我想從我的目錄中加載一個特定的圖像到我的應用程序的ImageView,但它不工作。整個事情變得空白。有人可以看一看,看看我的代碼出錯了嗎?謝謝!我的圖像無法加載到我的ImageView中。什麼地方出了錯?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_viewer);
ImageView imageView = (ImageView) findViewById(R.id.iv);
try {
//this toast below appears
Toast.makeText(getApplicationContext(), "try", Toast.LENGTH_LONG).show();
//below is the path for the image
Uri uri = Uri.parse("file://sdcard/myFoodDiary/snaps/default.jpg");
System.out.println("Image URI: " + uri.toString());
imageView.setImageURI(uri);
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(getApplicationContext(), "oops", Toast.LENGTH_LONG).show();
}
}
將圖像放到其他地方 - 您以前成功訪問過的地方 - 然後看看它是否有效。無論結果如果它有效或無效 - 你都會收集一些信息。 – Obversity
您是否添加了讀取SDCard的權限? –
@Obversity,它應該工作,雖然我從來沒有試過在別處訪問它。 – altern4te