java - Cannot cast double values as String to textview -


this question has answer here:

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

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -