android - com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Double to String -


my blog class here

package com.nego.lakshan.nego;   public class blog {  private string from; private string to; private string description; private string image; private string date; private double tolat; private double tolng; private double fromlat; private double fromlng;  public blog(){  }  public blog(string from, string to, string description, string image, string date, string tolat, string tolng, string fromlat, string fromlng) {     this.from = from;     this.to = to;     this.description = description;     this.image = image;     this.date = date;     this.tolat = double.parsedouble(tolat);     this.tolng = double.parsedouble(tolng);     this.fromlat = double.parsedouble(fromlat);     this.fromlng = double.parsedouble(fromlng); }    public string getfrom() {     return from; }  public void setfrom(string from) {     this.from = from; }  public string getto() {     return to; }  public void setto(string to) {     this.to = to; }  public string getimage() {     return image; }  public void setimage(string image) {     this.image = image; }  public string getdate() {     return date; }  public void setdate(string date) {     this.date = date; }  public double gettolat() {     return tolat; }  public void settolat(string tolat) {     this.tolat = double.parsedouble(tolat); }  public double gettolng() {     return tolng; }  public void settolng(string tolng) {     this.tolng = double.parsedouble(tolng); }  public double getfromlat() {     return fromlat; }  public void setfromlat(string fromlat) {     this.fromlat = double.parsedouble(fromlat); }  public double getfromlng() {     return fromlng; }  public void setfromlng(string fromlng) {     this.fromlng = double.parsedouble(fromlng); }   public string getdescription() {     return description; }  public void setdescription(string description) {     this.description = description; }  } 

and fragment class use view data in recycler view runtime database (firebase). , fragment class here

package com.nego.lakshan.nego;   import android.os.bundle; import android.support.annotation.nullable; import android.support.v4.app.fragment; import android.support.v7.widget.linearlayoutmanager; import android.support.v7.widget.recyclerview; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.textview; import android.widget.toast;   import com.firebase.ui.database.firebaserecycleradapter; import com.google.firebase.database.databasereference;     public class recieverfragment extends fragment {   public recieverfragment() {     // required empty public constructor }  private recyclerview mbloglist; private databasereference mdatabasereference; private view v;  @override  public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {     v=inflater.inflate(r.layout.fragment_reciever, container, false);       mbloglist= (recyclerview) v.findviewbyid(r.id.fragment);       mbloglist.sethasfixedsize(true);     mdatabasereference = firebasedatabase.getinstance().getreference().child("blog");          mbloglist.setlayoutmanager(new linearlayoutmanager(getcontext()));        toast.maketext(getcontext(),"mmmm",toast.length_short).show();     return v;      }  @override public void onstart() {     super.onstart();     firebaserecycleradapter<blog,blogviewholder>   mfirebaserecycleradapter=new firebaserecycleradapter<blog, blogviewholder> (blog.class,             r.layout.blog_item,             blogviewholder.class,             mdatabasereference) {         @override         protected void populateviewholder(blogviewholder viewholder, blog   model, int position) {               toast.maketext(getcontext(),"maaa",toast.length_short).show();               viewholder.setdate(model.getdate());             viewholder.setdescription(model.getdescription());             viewholder.setfrom(model.getfrom());             viewholder.setto(model.getto());             }     };     mbloglist.setadapter(mfirebaserecycleradapter); }  public static class blogviewholder extends  recyclerview.viewholder{      view mview;      public blogviewholder(view itemview) {         super(itemview);         mview=itemview;}     public void setdate(string date){         textview date = (textview) mview.findviewbyid(r.id.date);         date.settext(date);     }      public void setdescription(string description){         textview desc= (textview) mview.findviewbyid(r.id.description);         desc.settext(description);     }      public void setfrom(string from){         textview = (textview) mview.findviewbyid(r.id.from);         from.settext(from);     }      public void setto(string to){         textview = (textview) mview.findviewbyid(r.id.to);         to.settext(to);     }      } } 

and fragment layout file

<framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.nego.lakshan.nego.recieverfragment" android:id="@+id/place_holder">  <!-- todo: update blank fragment layout --> <android.support.v7.widget.recyclerview     android:scrollbars="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/fragment"> </android.support.v7.widget.recyclerview>   </framelayout> 

and im using cardview view (blog posts)

<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.cardview  xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="20dp">  <linearlayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="vertical"> <linearlayout android:layout_width="match_parent" android:layout_height="104dp" android:orientation="horizontal" android:weightsum="1">  <imageview     android:id="@+id/profilepic"     android:layout_width="wrap_content"     android:layout_height="match_parent"     android:layout_weight="1.05" />  <linearlayout     android:layout_width="244dp"     android:layout_height="wrap_content"     android:orientation="vertical">      <textview         android:id="@+id/name"         android:layout_width="match_parent"         android:layout_height="53dp" />      <textview         android:id="@+id/date"         android:layout_width="match_parent"         android:layout_height="52dp" /> </linearlayout>  </linearlayout>        <textview         android:id="@+id/description"         android:layout_width="match_parent"         android:layout_height="164dp" />      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="horizontal"         android:weightsum="1">          <linearlayout             android:layout_width="wrap_content"             android:layout_height="match_parent"             android:orientation="vertical"             android:layout_weight="0.16"             android:weightsum="1">             <textview                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:text="from"                 android:layout_weight="0.31" />             <textview                 android:layout_width="match_parent"                 android:layout_height="0dp"                 android:text="to"                 android:layout_weight="0.51" />          </linearlayout>          <linearlayout             android:layout_width="wrap_content"             android:layout_height="match_parent"             android:orientation="vertical"             android:layout_weight="0.88"             android:weightsum="1">              <textview                 android:id="@+id/from"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_weight="0.41" />              <textview                 android:id="@+id/to"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_weight="0.19" />          </linearlayout>          <linearlayout             android:layout_width="wrap_content"             android:layout_height="match_parent"             android:orientation="vertical">             <button                 android:layout_width="109dp"                 android:layout_height="wrap_content"                 android:text="fromlocation"/>             <button                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:text="tolocation"/>           </linearlayout>     </linearlayout>     <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="horizontal">         <button             android:layout_width="164dp"             android:layout_height="wrap_content"             android:text="direction"/>         <button             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:text="message"/>     </linearlayout>   </linearlayout>   </android.support.v7.widget.cardview> 

and im getting error , app crashes when call fragment

com.nego.lakshan.nego e/androidruntime: fatal exception: main                                                                    process:  com.nego.lakshan.nego, pid: 28426  com.google.firebase.database.databaseexception: failed convert value of  type java.lang.double string                                                                        @  com.google.android.gms.internal.zzbqi.zzad(unknown source)                                                                        @  com.google.android.gms.internal.zzbqi.zzb(unknown source)                                                                        @  com.google.android.gms.internal.zzbqi.zza(unknown source)                                                                        @  com.google.android.gms.internal.zzbqi.zzb(unknown source)                                                                        @  com.google.android.gms.internal.zzbqi$zza.zze(unknown source)                                                                        @  com.google.android.gms.internal.zzbqi$zza.zzag(unknown source)                                                                        @  com.google.android.gms.internal.zzbqi.zze(unknown source)                                                                        @  com.google.android.gms.internal.zzbqi.zzb(unknown source)                                                                        @  com.google.android.gms.internal.zzbqi.zza(unknown source)                                                                        @  com.google.firebase.database.datasnapshot.getvalue(unknown source)                                                                        @     com.firebase.ui.database.firebaserecycleradapter.parsesnapshot(firebaserecycler adapter.java:163)                                                                        @ com.firebase.ui.database.firebaserecycleradapter.getitem(firebaserecycleradapter.java:152)                                                                        @ com.firebase.ui.database.firebaserecycleradapter.onbindviewholder(firebaserecycleradapter.java:195)                                                                        @ android.support.v7.widget.recyclerview$adapter.onbindviewholder(recyclerview.java:6356)                                                                        @ android.support.v7.widget.recyclerview$adapter.bindviewholder(recyclerview.java:6389)                                                                        @ android.support.v7.widget.recyclerview$recycler.trybindviewholderbydeadline(recyclerview.java:5335)                                                                        @ android.support.v7.widget.recyclerview$recycler.trygetviewholderforpositionbydeadline(recyclerview.java:5598)                                                                        @ android.support.v7.widget.recyclerview$recycler.getviewforposition(recyclerview.java:5440)                                                                        @ android.support.v7.widget.recyclerview$recycler.getviewforposition(recyclerview.java:5436)                                                                        @ android.support.v7.widget.linearlayoutmanager$layoutstate.next(linearlayoutmanager.java:2224)                                                                        @ android.support.v7.widget.linearlayoutmanager.layoutchunk(linearlayoutmanager.java:1551)                                                                        @ android.support.v7.widget.linearlayoutmanager.fill(linearlayoutmanager.java:1511)                                                                        @ android.support.v7.widget.linearlayoutmanager.onlayoutchildren(linearlayoutmanager.java:595)                                                                        @ android.support.v7.widget.recyclerview.dispatchlayoutstep2(recyclerview.java:3583)                                                                        @ android.support.v7.widget.recyclerview.dispatchlayout(recyclerview.java:3312)                                                                        @ android.support.v7.widget.recyclerview.consumependingupdateoperations(recyclerview.java:1648)                                                                        @ android.support.v7.widget.recyclerview$1.run(recyclerview.java:343)                                                                        @ android.view.choreographer$callbackrecord.run(choreographer.java:767)                                                                        @ android.view.choreographer.docallbacks(choreographer.java:580)                                                                        @ android.view.choreographer.doframe(choreographer.java:549)                                                                        @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:753)                                                                        @ android.os.handler.handlecallback(handler.java:739)                                                                        @ android.os.handler.dispatchmessage(handler.java:95)                                                                        @ android.os.looper.loop(looper.java:135)                                                                        @ android.app.activitythread.main(activitythread.java:5319)                                                                        @ java.lang.reflect.method.invoke(native method)                                                                        @ java.lang.reflect.method.invoke(method.java:372)                                                                        @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1016)                                                                        @ com.android.internal.os.zygoteinit.main(zygoteinit.java:811) 

please, me on this.

the problem in blog.class. while declaring following variables double, class constructor accepting strings initialize it:

private double tolat; private double tolng; private double fromlat; private double fromlng; 

now problem firebase database going save per definition here , in 'get' methods i.e. double. when retrieving blogs, database class constructor failing convert string.

please fix variable types consistent declarations , error should go away.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -