尝试运行谷歌驱动程序示例时发生java.lang.NullPointerException [英] java.lang.NullPointerException while trying to run google driver example
问题描述
大家好,我想用google drive api来完成一些任务,不过我刚接触Drive API,OAuth2.0协议。遵循这个例子,我最终得到了这个例外,我真的不知道不知道发生了什么我复制了该示例,如同复制/过去,添加了我的CLIENT_ID,CLIENT_SECRET和REDIRECT_URI,但没有任何结果。
这是错误
线程mainjava中的异常.lang.NullPointerException
,位于com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191)
com.google。 api.client.util.Preconditions.checkNotNull(Preconditions.java:127)
at com.google.api.client.json.jackson2.JacksonFactory.createJsonParser(JacksonFactory.java:96)
at com。 google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:85)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com。 google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:88)
,位于com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.execute(GoogleAuthorizationCodeTokenRequest.java:158)
at com .gpaps.apps.expensesmanager.google.drive.DriverReportExporter.main(DriverReportExporter.java:47)
当我调用 GoogleTokenResponse response = flow.newTokenRequest(code).setRedirectUri(REDIRECT_URI).execute();
我检查了每个对象,并且一切正常。
感谢您提前帮助我:) 解决方案
错误通过客户端库源代码,NPE似乎源于 response.getContent()
返回null在 TokenResponseException.from()
。我不知道为什么响应没有任何内容,但是这是一个错误,即客户端库不会检测到这个状态并更合适地处理它。目前已有公开问题该项目的问题跟踪解决问题。
Hi guys I want to use google drive api to do some task, however I new to Drive API, OAuth2.0 protocol too. Following this example I end up with this exception which I really don't understand what is happening I copied the example as is copy/past, added my CLIENT_ID, CLIENT_SECRET and REDIRECT_URI but nothing.
Here is the error
Exception in thread "main" java.lang.NullPointerException
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191)
at com.google.api.client.util.Preconditions.checkNotNull(Preconditions.java:127)
at com.google.api.client.json.jackson2.JacksonFactory.createJsonParser(JacksonFactory.java:96)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:85)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:88)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.execute(GoogleAuthorizationCodeTokenRequest.java:158)
at com.gpaps.apps.expensesmanager.google.drive.DriverReportExporter.main(DriverReportExporter.java:47)
The exception is thrown when I call GoogleTokenResponse response = flow.newTokenRequest(code).setRedirectUri(REDIRECT_URI).execute();
I checked every object and everything was Ok.
Thanks for helping me in advance :)
Tracing the error through the client library source code, the NPE appears to stem from response.getContent()
returning null here in TokenResponseException.from()
. I'm not sure why the response would not have any content, but it's a bug that the client library doesn't detect this state and handle it more appropriately. There is already an open issue on the project's issue tracker to fix the problem.
这篇关于尝试运行谷歌驱动程序示例时发生java.lang.NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!