[英]OutOfMemory Error in downloading file from Google Drive using Java SDK API
[英](Java) Error downloading File from Google Drive
我在代碼中遇到了這3個錯誤:
private static void downloadFile(Drive service, String fileId) {
try {
OutputStream outputStream = new FileOutputStream("test.csv");
service.files().export(fileId, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet").executeMediaAndDownloadTo(outputStream);
} catch (IOException e) {
// An error occurred.
e.printStackTrace();
}
}
錯誤結果如下:
googleBaru.mainClass.main(mainClass.java:60)上googleBaru.mainClass.downloadFile(mainClass.java:51)處的線程“ main”中的java.lang.NullPointerException異常
我希望任何人都可以修復我的代碼,或者我應該怎么做才能調用該方法(使用參數service和fileId)
非常感謝,抱歉我的英語不好
我在代碼中遇到了這3個錯誤。
實際上,這是一個堆棧跟蹤...,它描述的是一個錯誤,而不是三個。
該錯誤在您的mainclass.java
文件的第51行上。 那就是這個:
service.files().export(fileId,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet").
executeMediaAndDownloadTo(outputStream);
假定該service
應該是Drive
對象,那么從Java角度來看這個:
service
參考可以為空, files()
方法可能返回了null
(我認為這是不可能的),或者 export()
方法可能返回了null
(我認為這是不可能的)。 根據我對Drive API javadocs的閱讀,出現了“不可能”的情況。
簡而言之,最合理的解釋是您的service
引用為null
。 找出原因,並解決原因。
@TimBiegeleisen關於文件路徑的評論也可能是正確的,但這不是您看到的NullPointerException
的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.