firestoreoptions.getService 上的 Firestore 空指针异常

Firestore Null Pointer Exception on firestoreoptions.getService

您好,我正在使用带有 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 file/library。任何帮助将不胜感激。

GOOGLE_APPLICATION_CREDENTIALS

必须将环境变量与正确的凭据文件路径和名称一起添加到服务器上的 运行 firestore。