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

10,409

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

Share:
10,409
muchamaze
Author by

muchamaze

Updated on June 04, 2022

Comments

  • muchamaze
    muchamaze about 2 years

    [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);
    
  • mehmet
    mehmet over 7 years
    you are number1
  • Shubham AgaRwal
    Shubham AgaRwal about 6 years
    Is it possible to automatically typecast to string ?
  • Ankur Aggarwal
    Ankur Aggarwal about 6 years
    @Killer As far as I know, Firebase has no such provision
  • ertuzun
    ertuzun about 3 years
    I was using same property name for different classes' different variables. So it causes a cast exception. When I changed the property names of variables it is solved. Thank you.