java - Cannot cast double values as String to textview -
this question has answer here:
- what nullpointerexception, , how fix it? 12 answers
i got null pointer exeption error on attempt invoke virtual method void android.widget.textview.settext(java.lang.charsequence)'
on null object reference.
public class mainactivity { textview servingqueue; }
this oncreate
databasereference mrootref = firebasedatabase.getinstance().getreference(); databasereference mservingqueue = mrootref.child("servingqueue"); servingqueue = (textview) findviewbyid(r.id.queueserving); mservingqueue.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { double number = datasnapshot.getvalue(double.class); servingqueue.settext(string.valueof(number)); } @override public void oncancelled(databaseerror databaseerror) { }
the error appeared right on
servingqueue.settext(string.valueof(number));
it not want pass value firebase textview. force close app upon loading activity.
first cast double double(primitive) cast string
double number = datasnapshot.getvalue(double.class); double d=number.doublevalue(); servingqueue.settext(string.valueof(d));
Comments
Post a Comment