Reputation: 704
Hello I'm having a problem with nulls when going into this game activity. Here I leave you the code of the error and the methods with the lines of the crash. Maybe I'm missunderstanding something, sorry for my english.
Error code:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.venomapps.tictactoeonline, PID: 20007
java.lang.NullPointerException: Provided document path must not be null.
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:906)
at com.google.firebase.firestore.CollectionReference.document(com.google.firebase:firebase-firestore@@21.4.0:103)
at com.venomapps.tictactoeonline.Activities.GameActivity.gameListener(GameActivity.java:136)
at com.venomapps.tictactoeonline.Activities.GameActivity.onStart(GameActivity.java:131)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
at android.app.Activity.performStart(Activity.java:7157)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2937)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Method lines: `
@Override
protected void onStart() {
super.onStart();
gameListener();
}
private void gameListener(){
listenerRegistration = database.collection("games")
.document(gameId)
.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
if(e != null){
Toast.makeText(GameActivity.this, getString(R.string.try_again_later), Toast.LENGTH_LONG).show();
return;
}
assert documentSnapshot != null;
String source = documentSnapshot.getMetadata().hasPendingWrites() ? "Local" : "Server";
if(documentSnapshot.exists() && source.equals("Server")){
// Parsing documentSnapshot to Game object.
game = documentSnapshot.toObject(Game.class);
if(player1Name.isEmpty() || player2Name.isEmpty()){
getPlayerNames();
}
updateUI();
}
updatePlayersUI();
}
});
}
Upvotes: 1
Views: 1588
Reputation: 317372
You're not including enough information in your question to know exactly what's going on, but the error message is telling you that you can't pass null to document()
. That means the argument gameId
is null. You're going to have to think carefully about what value you think it should have, and do some debugging to figure out why it's null instead.
Upvotes: 4