Skip to content
Advertisement

Trying to retrieve data from Firebase and get this error: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

The database

I build an application and I’m trying to retrieve user info from Firebase. After the registration form, I have a new activity where the users need to write their personal info and that information is stored in firebase. Then, in my navigation drawer, I have an activity, called “AccountActivity”, where the user cand see their personal info saved into the database. I tried to write some code in order to do this, but when I try to access the AccountActivity, it is empty..doesn’t retrieve user info from firebase and I get this error:

SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero-length

Do you know what is wrong and what can I do in order to fix it?

This is the data I have in firebase, in JSON format, so the database is not empty:

JavaScript

User class:

JavaScript

AccountActivity:

JavaScript

activity_account.xml:

JavaScript

In XML file, I put some text views, but with no text, just black space, and in string.xml I have something like this for each TextView form activity_account.xml: <string name="textviewGenderDb">" "</string>

So my questions are: I didn’t something wrong in the XML file, or the code is written is wrong? I don’t know where is the problem and why I get this error. Thanks for your help!

Advertisement

Answer

I did something wrong in the XML file, or the code is written wrong?

There are three main problems.

  1. The fields in your User class are public. If you want to use getters and setters, make all of them private.

  2. Your databaseReference points to the root of your database but users are added within the User node. So in order to get all users, a call to .child("User") should be added. So please check the following lines of code:

    JavaScript

The result in the logcat will be:

JavaScript

Two thinks you should note. First, you can directly map a node from the database to a User object, without the need to create a new object and set the values. Second, the node should be more likely to be named Users or users and not simply User, because in that node exist multiple users and not a single one.

  1. Because you are iterating on a node that contains multiple users, you should use instead of TextView object a ListView. In this way you can add each details in a row.
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement