简体   繁体   English

firestoreoptions.getService上的Firestore空指针异常

[英]Firestore Null Pointer Exception on firestoreoptions.getService

Hi i am using SmartFoxServer with a Java extension. 嗨,我将SmartFoxServer与Java扩展一起使用。 Inside that extension i am trying to get firestore instance. 在该扩展程序内部,我尝试获取Firestore实例。 Below is the code i am using to connect to service that is working fine inside IDE (Eclipse). 下面是我用来连接到在IDE(Eclipse)中运行良好的服务的代码。 but when i deploy my extension on SmartFoxServer it gives a null pointer exception on firestoreOptions.getService 但是,当我在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);
            }

Here is the exception i am getting. 这是我得到的例外。

    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)

i am new to firestore. 我是新来的消防员。 Don't know if any jar file/library is missing to run this code on server. 不知道是否缺少任何jar文件/库来在服务器上运行此代码。 any help would be appreciated. 任何帮助,将不胜感激。

GOOGLE_APPLICATION_CREDENTIALS GOOGLE_APPLICATION_CREDENTIALS

environment variable must be added with the correct credential's file path and name to run firestore on server. 必须为环境变量添加正确凭据的文件路径和名称,才能在服务器上运行firestore。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM