Ad

Firebase.database.DatabaseException: Failed To Convert Value Of Type Java.lang.Long To String

[This is the database]

firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String

I am trying to add this data to a FirebaserecyclerAdapter and getting this error

Here is the database reference

    databaseReference = FirebaseDatabase.getInstance().getReference().child("questions");

this is how I have used the RecyclerViewAdapter

  FirebaseRecyclerAdapter<History, HistoryViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<History, HistoryViewHolder>(
            History.class, R.layout.history_list_item, HistoryViewHolder.class, databaseReference) {
        @Override
        protected void populateViewHolder(HistoryViewHolder viewHolder, History model, int position) {
            viewHolder.setMyanswer(model.getMyAnswer());
            viewHolder.setCorrentAnswer(model.getCorrectAnswer());
            viewHolder.setImageUrl(getApplicationContext(), model.getImageUrl());

        }
    };
    recyclerView.setAdapter(firebaseRecyclerAdapter);
Ad

Answer

The two nodes in your database indeed have a mismatch of data type :

myAnswer : "21"
myAnswer : 11

If you want this to be a String, it should instead be :

myAnswer : "21"
myAnswer : "11"

Or, have them as long :

myAnswer : 21
myAnswer : 11

Make sure you take care of consistency while adding data

Ad
source: stackoverflow.com
Ad