Java firestoreoptions.getService上的Firestore空指针异常
您好,我正在使用带有Java扩展的SmartFoxServer。在该扩展中,我正在尝试获取firestore实例。下面是我用来连接到IDE(Eclipse)中运行良好的服务的代码。但当我在SmartFoxServer上部署扩展时,firestoreOptions.getService上会出现空指针异常Java firestoreoptions.getService上的Firestore空指针异常,java,linux,google-cloud-firestore,smartfoxserver,Java,Linux,Google Cloud Firestore,Smartfoxserver,您好,我正在使用带有Java扩展的SmartFoxServer。在该扩展中,我正在尝试获取firestore实例。下面是我用来连接到IDE(Eclipse)中运行良好的服务的代码。但当我在SmartFoxServer上部署扩展时,firestoreOptions.getService上会出现空指针异常 String jsonPath = "data/************.json"; GoogleCredentials credentials = null;
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)
com.google.cloud.firestore.FirestoreException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
例外:com.google.cloud.firestore.FirestoreException
消息:java.lang.NullPointerException
描述:扩展初始化失败。
+--- --- ---+
堆栈跟踪:
+--- --- ---+
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)
FirestoreImpl.(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.quick.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)
我是新来的消防商店。不知道在服务器上运行此代码是否缺少任何jar文件/库。任何帮助都将不胜感激
GOOGLE\u应用程序\u凭据
必须使用正确的凭据文件路径和名称添加环境变量,才能在服务器上运行firestore。您确定
credentials
对象已正确初始化吗?是。我已通过记录凭据对象进行了检查。它有正确的值。