【发布时间】:2018-07-10 22:52:40
【问题描述】:
谁能告诉我我的做法是否正确?
File directoryToStore;
directoryToStore = getBaseContext().getExternalFilesDir("MyFiles");
Bitmap b = ThumbnailUtils.createVideoThumbnail(directoryToStore + "/" + SavedVideoName, 3);
File newFile = new File(directoryToStore, SavedVideoName.replace(".mp4", ".jpg"));
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(newFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
b.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
我正在尝试从视频创建缩略图,但对于某些FileOutputStream 返回null。
我检查了File newFile = new File(directoryToStore, SavedVideoName.replace(".mp4", ".jpg")); 的路径,它返回了正确的路径。
视频存在于我提供的位置并且我有权限。我不明白为什么它给了我一个空指针?
【问题讨论】:
-
我认为你需要创建文件。
标签: java android nullpointerexception