作者:JieGe木 | 来源:互联网 | 2023-01-21 11:53
我正在按照教程说明如何使用Java连接谷歌表.它使用gradle来获取依赖关系
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'Quickstart'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.api-client:google-api-client:1.22.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.22.0'
compile 'com.google.apis:google-api-services-sheets:v4-rev483-1.22.0'
}
当我从IntelliJ内部运行示例QuickStart.java类时,我可以看到周围的错误
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.sheets.v4.SheetsScopes;
import com.google.api.services.sheets.v4.model.*;
import com.google.api.services.sheets.v4.Sheets;
说找不到图书馆.在IntelliJ的工具栏中,我转到了文件 - >项目结构 - >依赖项,并添加了build.gradle中的3个项目.之后,围绕进口的错误消失了.当我上课时,我得到了
objc[1649]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x102cf14c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x102db94e0). One of the two will be used. Which one is undefined.
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.(Reader.java:78)
at java.io.InputStreamReader.(InputStreamReader.java:72)
at Quickstart.authorize(Quickstart.java:67)
at Quickstart.getSheetsService(Quickstart.java:90)
at Quickstart.main(Quickstart.java:98)
如果我使用gradle -q run在终端中运行它,一切都会完成.不知何故,价值
InputStream in = Quickstart.class.getResourceAsStream("/client_secret.json");
在IntelliJ中运行时为null,但在终端中运行时不为null
编辑:这是项目树的样子