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

Databases

Joseph Wagner
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Wagner
Android Development Techdegree Graduate 27,137 Points

Firebase - Reading Data

My data structure:

I'm having trouble reading values from Firebase. If I delete the timelog child then it seems as if Users is the root of the datasnapshot and it will function if I remove users like this:

uInfo.setFirstName(ds.child("yAnJF2IWhvTmJBWYY6FL6g7CzKB2-001").getValue(UserInfo.class).getFirstName());

I keep getting a null pointer exception if I try to access like I'm currently doing. How can I access the values from TimeLog?

Here's the data structure. data structure

private void showData(DataSnapshot dataSnapshot) {
        for(DataSnapshot ds : dataSnapshot.getChildren()){
            UserInfo uInfo = new UserInfo();
            uInfo.setFirstName(ds.child("Users/yAnJF2IWhvTmJBWYY6FL6g7CzKB2-001").getValue(UserInfo.class).getFirstName());

            String firstName = uInfo.getFirstName();
            welcome.setText("Hello there " +firstName);
        }
    }