![](/img/trans.png)
[英]Null Pointer Exception in RecyclerView within Fragment with Firestore
[英]Firestore Null Pointer Exception on firestoreoptions.getService
嗨,我將SmartFoxServer與Java擴展一起使用。 在該擴展程序內部,我嘗試獲取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)
我是新來的消防員。 不知道是否缺少任何jar文件/庫來在服務器上運行此代碼。 任何幫助,將不勝感激。
GOOGLE_APPLICATION_CREDENTIALS
必須為環境變量添加正確憑據的文件路徑和名稱,才能在服務器上運行firestore。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.