Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Receiving Realtime Messages with Firebase

'message' and 'username' are switched?

So when viewing the Realtime Database in Firebase under each message node it is showing that message: "TestUser" and username: "This is a test message". So somewhere the message and username are getting switched. Being relatively new to Firebase and java in general, I have absolutely no idea where this is happening.

This is also how they are showing on my emulators. I have the username displaying at the top it large font and bold with the message displaying underneath before the date.

Surely this is incorrect, even though in some of the videos in this course both Michaels' emulators and Firebase Database are displaying the same as what mine are.

In this particular video it seems that when Michael sends a message from one emulator the username and message are switched yet when he sends a message from the second emulator they are display as they should with the message on the top with the username underneath.

Any help on this would be great.

1 Answer

In the MessagingActivity Class in the pushMessageToFireBase() method, insure the following line is written like this:

Message messageToSend = new Message(username, messageContent, now);

and not: Message messageToSend = new Message(messageContent, username, now);

Regards,