gpt4 book ai didi

java - firestoreoptions.getService 上的 Firestore 空指针异常

转载 作者:太空宇宙 更新时间:2023-11-04 12:04:11 25 4
gpt4 key购买 nike

您好,我正在使用带有 Java 扩展的 SmartFoxServer。在该扩展中,我正在尝试获取 firestore 实例。下面是我用来连接到在 IDE (Eclipse) 中运行良好的服务的代码。但是当我在 SmartFoxServer 上部署我的扩展时,它在 firestoreOptions.getService 上给出了一个空指针异常

String jsonPath = "data/************.json";
GoogleCredentials credentials = null;
try {
credentials = GoogleCredentials.fromStream(new FileInputStream(jsonPath))
.createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
} catch (FileNotFoundException e1) {
trace("Exception" + e1.toString());
} catch (IOException e1) {
trace("Exception" + e1.toString());
}

FirestoreOptions firestoreOptions = FirestoreOptions.newBuilder().setCredentials(credentials).build();

Firestore db = firestoreOptions.getService();
this.db = db;
try {
run();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
trace("Exception : " + e);
}

这是我遇到的异常。

    com.google.cloud.firestore.FirestoreException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: com.google.cloud.firestore.FirestoreException
Message: java.lang.NullPointerException
Description: Extension initialization failed.
+--- --- ---+
Stack Trace:
+--- --- ---+
com.google.cloud.firestore.FirestoreException.networkException(FirestoreException.java:70)
com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:81)
com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:71)
com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:506)
com.google.cloud.firestore.FirestoreOptions.getFirestoreRpc(FirestoreOptions.java:306)
com.google.cloud.firestore.FirestoreImpl.<init>(FirestoreImpl.java:76)
com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:62)
com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:55)
com.google.cloud.ServiceOptions.getService(ServiceOptions.java:493)
sfs2x.extension.game.quiz.QuizExtension.init(QuizExtension.java:159)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:303)
com.smartfoxserver.v2.entities.managers.SFSZoneManager.createZone(SFSZoneManager.java:426)

我是 Firestore 的新手。不知道是否缺少任何 jar 文件/库以在服务器上运行此代码。任何帮助将不胜感激。

最佳答案

GOOGLE_APPLICATION_CREDENTIALS

环境变量必须添加正确的凭据文件路径和名称才能在服务器上运行 firestore。

关于java - firestoreoptions.getService 上的 Firestore 空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51274380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com