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
Author by
muchamaze
Updated on June 04, 2022Comments
-
muchamaze about 2 years
[
]
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 over 7 yearsyou are number1
-
Shubham AgaRwal about 6 yearsIs it possible to automatically typecast to string ?
-
Ankur Aggarwal about 6 years@Killer As far as I know, Firebase has no such provision
-
ertuzun about 3 yearsI 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.