在我的代码中,我已成功将一些图像存储到 SDCARD 。现在,我尝试从 SDCARD 中读取这些图片,但我在尝试阅读文件时收到NullPointerException
。
这是我的代码:
// list of available files in path
ArrayList<String> f = new ArrayList<String>();
File[] listFile;
String ExternalStorageDirectoryPath = Environment.getExternalStorageDirectory().getAbsolutePath();
String targetPath = ExternalStorageDirectoryPath + "/saved_images";
Toast.makeText(getApplicationContext(), targetPath, Toast.LENGTH_LONG).show();
File targetDirector = new File(targetPath);
File[] files = targetDirector.listFiles();
for (File file : files){
// This line shows error
imageAdapter.add(file.getAbsolutePath());
}
答案 0 :(得分:0)
你应该添加两张支票。
if ( !targetDirector.exists())
return; and display toast
if (files==null)
return; and display toast