User values aren't being assigned to Firebase Database










0















So right now I have my app set up so that a user can create an open game, and then a player can join this open game and become user2 or player2. This works just find, a player clicks the join button and appear in the lobby database as 'user2'. As shown below



enter image description here



This is a pretty simple thing, a player makes a game with the user2 equal to null, and then when somebody clicks join they replace null with their user information. This is the code used when a player joins a game.



private void joinGame() 
second = new User(userName, 0, getSide(), FirebaseAuth.getInstance().getUid());
gm.setUser2(second);



And then that method is called whenever someone clicks Join. I also have setup a Toast that displays the user2's information by calling



gm.getUser2().getUserName();


which displays their username, and that works just fine. So I know that when I use the setter setUser2(second), it is working properly



Now to my problem, which doesn't make much sense to me. After somebody joins a game, the Lobby game is deleted and an active game database node is added.



It is added through this code:



public static FCGameMaker beginGame;

private void createGame()
beginGame = new FCGameMaker(gm.getUser1(), gm.getUser2(), false, false);
FlipCoinGames.child(userName).setValue(beginGame);



And this is my FCGameMaker constructor



public FCGameMaker(User player1, User player2, boolean gameStarted, boolean gameFinished) 
this.player1 = player1;
this.player2 = player2;
this.gameStarted = gameStarted;
this.gameFinished = gameFinished;



But when the database is created, player2 does not appear.



This is what the database looks like after the createGame() method is called



enter image description here



And I have no idea why the second user is not being added, because I am positive that gm.setUser2(second) is being called before this createGame() method, so I am not sure why this is not working.



Any help?



private FCLobbyMaker gm;

gm = dataSnapshot.getValue(FCLobbyMaker.class);


And then my FCGameMaker constructor is already posted, the rest of that class is just getters and setters for the variables.










share|improve this question
























  • You're probably overwriting a new value to that node.

    – jake
    Nov 15 '18 at 1:45











  • @jake But whenever the Toast prints, after the game is created, the correct information for user2 appears, so I do not think that that is the case

    – CoderKlipto
    Nov 15 '18 at 1:46












  • Can you please post the code of variable gm

    – jake
    Nov 15 '18 at 1:51











  • @jake added it to the bottom of the post

    – CoderKlipto
    Nov 15 '18 at 2:31















0















So right now I have my app set up so that a user can create an open game, and then a player can join this open game and become user2 or player2. This works just find, a player clicks the join button and appear in the lobby database as 'user2'. As shown below



enter image description here



This is a pretty simple thing, a player makes a game with the user2 equal to null, and then when somebody clicks join they replace null with their user information. This is the code used when a player joins a game.



private void joinGame() 
second = new User(userName, 0, getSide(), FirebaseAuth.getInstance().getUid());
gm.setUser2(second);



And then that method is called whenever someone clicks Join. I also have setup a Toast that displays the user2's information by calling



gm.getUser2().getUserName();


which displays their username, and that works just fine. So I know that when I use the setter setUser2(second), it is working properly



Now to my problem, which doesn't make much sense to me. After somebody joins a game, the Lobby game is deleted and an active game database node is added.



It is added through this code:



public static FCGameMaker beginGame;

private void createGame()
beginGame = new FCGameMaker(gm.getUser1(), gm.getUser2(), false, false);
FlipCoinGames.child(userName).setValue(beginGame);



And this is my FCGameMaker constructor



public FCGameMaker(User player1, User player2, boolean gameStarted, boolean gameFinished) 
this.player1 = player1;
this.player2 = player2;
this.gameStarted = gameStarted;
this.gameFinished = gameFinished;



But when the database is created, player2 does not appear.



This is what the database looks like after the createGame() method is called



enter image description here



And I have no idea why the second user is not being added, because I am positive that gm.setUser2(second) is being called before this createGame() method, so I am not sure why this is not working.



Any help?



private FCLobbyMaker gm;

gm = dataSnapshot.getValue(FCLobbyMaker.class);


And then my FCGameMaker constructor is already posted, the rest of that class is just getters and setters for the variables.










share|improve this question
























  • You're probably overwriting a new value to that node.

    – jake
    Nov 15 '18 at 1:45











  • @jake But whenever the Toast prints, after the game is created, the correct information for user2 appears, so I do not think that that is the case

    – CoderKlipto
    Nov 15 '18 at 1:46












  • Can you please post the code of variable gm

    – jake
    Nov 15 '18 at 1:51











  • @jake added it to the bottom of the post

    – CoderKlipto
    Nov 15 '18 at 2:31













0












0








0








So right now I have my app set up so that a user can create an open game, and then a player can join this open game and become user2 or player2. This works just find, a player clicks the join button and appear in the lobby database as 'user2'. As shown below



enter image description here



This is a pretty simple thing, a player makes a game with the user2 equal to null, and then when somebody clicks join they replace null with their user information. This is the code used when a player joins a game.



private void joinGame() 
second = new User(userName, 0, getSide(), FirebaseAuth.getInstance().getUid());
gm.setUser2(second);



And then that method is called whenever someone clicks Join. I also have setup a Toast that displays the user2's information by calling



gm.getUser2().getUserName();


which displays their username, and that works just fine. So I know that when I use the setter setUser2(second), it is working properly



Now to my problem, which doesn't make much sense to me. After somebody joins a game, the Lobby game is deleted and an active game database node is added.



It is added through this code:



public static FCGameMaker beginGame;

private void createGame()
beginGame = new FCGameMaker(gm.getUser1(), gm.getUser2(), false, false);
FlipCoinGames.child(userName).setValue(beginGame);



And this is my FCGameMaker constructor



public FCGameMaker(User player1, User player2, boolean gameStarted, boolean gameFinished) 
this.player1 = player1;
this.player2 = player2;
this.gameStarted = gameStarted;
this.gameFinished = gameFinished;



But when the database is created, player2 does not appear.



This is what the database looks like after the createGame() method is called



enter image description here



And I have no idea why the second user is not being added, because I am positive that gm.setUser2(second) is being called before this createGame() method, so I am not sure why this is not working.



Any help?



private FCLobbyMaker gm;

gm = dataSnapshot.getValue(FCLobbyMaker.class);


And then my FCGameMaker constructor is already posted, the rest of that class is just getters and setters for the variables.










share|improve this question
















So right now I have my app set up so that a user can create an open game, and then a player can join this open game and become user2 or player2. This works just find, a player clicks the join button and appear in the lobby database as 'user2'. As shown below



enter image description here



This is a pretty simple thing, a player makes a game with the user2 equal to null, and then when somebody clicks join they replace null with their user information. This is the code used when a player joins a game.



private void joinGame() 
second = new User(userName, 0, getSide(), FirebaseAuth.getInstance().getUid());
gm.setUser2(second);



And then that method is called whenever someone clicks Join. I also have setup a Toast that displays the user2's information by calling



gm.getUser2().getUserName();


which displays their username, and that works just fine. So I know that when I use the setter setUser2(second), it is working properly



Now to my problem, which doesn't make much sense to me. After somebody joins a game, the Lobby game is deleted and an active game database node is added.



It is added through this code:



public static FCGameMaker beginGame;

private void createGame()
beginGame = new FCGameMaker(gm.getUser1(), gm.getUser2(), false, false);
FlipCoinGames.child(userName).setValue(beginGame);



And this is my FCGameMaker constructor



public FCGameMaker(User player1, User player2, boolean gameStarted, boolean gameFinished) 
this.player1 = player1;
this.player2 = player2;
this.gameStarted = gameStarted;
this.gameFinished = gameFinished;



But when the database is created, player2 does not appear.



This is what the database looks like after the createGame() method is called



enter image description here



And I have no idea why the second user is not being added, because I am positive that gm.setUser2(second) is being called before this createGame() method, so I am not sure why this is not working.



Any help?



private FCLobbyMaker gm;

gm = dataSnapshot.getValue(FCLobbyMaker.class);


And then my FCGameMaker constructor is already posted, the rest of that class is just getters and setters for the variables.







java android firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 8:59









PradyumanDixit

2,1872819




2,1872819










asked Nov 15 '18 at 0:05









CoderKliptoCoderKlipto

617




617












  • You're probably overwriting a new value to that node.

    – jake
    Nov 15 '18 at 1:45











  • @jake But whenever the Toast prints, after the game is created, the correct information for user2 appears, so I do not think that that is the case

    – CoderKlipto
    Nov 15 '18 at 1:46












  • Can you please post the code of variable gm

    – jake
    Nov 15 '18 at 1:51











  • @jake added it to the bottom of the post

    – CoderKlipto
    Nov 15 '18 at 2:31

















  • You're probably overwriting a new value to that node.

    – jake
    Nov 15 '18 at 1:45











  • @jake But whenever the Toast prints, after the game is created, the correct information for user2 appears, so I do not think that that is the case

    – CoderKlipto
    Nov 15 '18 at 1:46












  • Can you please post the code of variable gm

    – jake
    Nov 15 '18 at 1:51











  • @jake added it to the bottom of the post

    – CoderKlipto
    Nov 15 '18 at 2:31
















You're probably overwriting a new value to that node.

– jake
Nov 15 '18 at 1:45





You're probably overwriting a new value to that node.

– jake
Nov 15 '18 at 1:45













@jake But whenever the Toast prints, after the game is created, the correct information for user2 appears, so I do not think that that is the case

– CoderKlipto
Nov 15 '18 at 1:46






@jake But whenever the Toast prints, after the game is created, the correct information for user2 appears, so I do not think that that is the case

– CoderKlipto
Nov 15 '18 at 1:46














Can you please post the code of variable gm

– jake
Nov 15 '18 at 1:51





Can you please post the code of variable gm

– jake
Nov 15 '18 at 1:51













@jake added it to the bottom of the post

– CoderKlipto
Nov 15 '18 at 2:31





@jake added it to the bottom of the post

– CoderKlipto
Nov 15 '18 at 2:31












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310615%2fuser-values-arent-being-assigned-to-firebase-database%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310615%2fuser-values-arent-being-assigned-to-firebase-database%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Museum of Modern and Contemporary Art of Trento and Rovereto

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully