我正在使用metadata extractor API從圖像中提取元數據。然後我使用Java創建一個包含所有數據的.txt文件。但是,當我運行該文件時,我有nullpointexception。創建文本文件時出錯Java
我知道某些內容正在輸出,因爲它在NetBeans中提供的輸出框中打印出來。
類創建文件:
private void metadataImageButtonMouseClicked(java.awt.event.MouseEvent evt) {
System.out.println(MetaData.getTags());
try {
File report;
report = new File("report.txt");
report.createNewFile();
FileWriter kmlStream = new FileWriter("report.txt");
try (BufferedWriter out = new BufferedWriter(kmlStream)) {
out.write(MetaData.allTags);
statusUpdateMessage.setText("Report file created");
System.out.println("New file \"Report.txt\" has been created to the current directory");
}
} catch (IOException ex) {
Logger.getLogger(MetaDataExtractor.class.getName()).log(Level.SEVERE, null, ex);
}
檢索所有元數據
Metadata metadata = ImageMetadataReader.readMetadata(jpegFile);
for (Directory directory : metadata.getDirectories()) {
for (Tag allTags : directory.getTags()) {
System.out.println(allTags);
}
}
} catch (ImageProcessingException ex) {
Logger.getLogger(MetaData.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(MetaData.class.getName()).log(Level.SEVERE, null, ex);
}
return allTags;
我首先想到的是有返回類型爲字符串,但它不會讓我做。歡迎任何建議,因爲我對Java不夠強大。 Here are the errors
在此先感謝。