android - Firebase Database Failed to convert value of type java.util.ArrayList to String -


i can not recycler view work houses have on firebase database. trying display houses on starting activity no luck now. here have tried: sorry many lines of code, wanted show complete code in order explain better. my database

on onstart() try populate reyclerview:

public class mainactivity extends appcompatactivity             implements navigationview.onnavigationitemselectedlistener {      private firebaseauth mauth;     private databasereference mdatabase;     private databasereference mdatabasehouses;      private string uid;     private string email;     private string username;      private static final int rc_sign_in = 123;      private recyclerview mrecyclerview;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);         setsupportactionbar(toolbar);          mauth = firebaseauth.getinstance();         mdatabase = firebasedatabase.getinstance().getreference();         mdatabasehouses = firebasedatabase.getinstance().getreference().child("houses");          mrecyclerview = (recyclerview) findviewbyid(r.id.main_recycler_houses);         mrecyclerview.sethasfixedsize(true);         mrecyclerview.setlayoutmanager(new linearlayoutmanager(this));           drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);         actionbardrawertoggle toggle = new actionbardrawertoggle(                 this, drawer, toolbar, r.string.navigation_drawer_open, r.string.navigation_drawer_close);         drawer.setdrawerlistener(toggle);         toggle.syncstate();          navigationview navigationview = (navigationview) findviewbyid(r.id.nav_view);         navigationview.setnavigationitemselectedlistener(this);     }      @override     protected void onstart() {         super.onstart();         firebaseuser currentuser = mauth.getcurrentuser();         if (currentuser == null) {             signuser();         }          firebaserecycleradapter<houses, housesviewholder> mhousesrecycleradapter = new firebaserecycleradapter<houses, housesviewholder>(                 houses.class,                 r.layout.house_single,                 housesviewholder.class,                 mdatabasehouses         ) {             @override             protected void populateviewholder(housesviewholder viewholder, houses house, int position) {                 viewholder.sethousename(house.gethouse_name());             }         };          mrecyclerview.setadapter(mhousesrecycleradapter);     }      private static class housesviewholder extends recyclerview.viewholder {         view mview;          public housesviewholder(view itemview) {             super(itemview);             mview = itemview;         }           void sethousename(string house_name) {             textview house_name_tv = (textview) mview.findviewbyid(r.id.single_house_name_tv);             house_name_tv.settext(house_name);         }     }      @override     protected void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);         if (requestcode == rc_sign_in) {             idpresponse response = idpresponse.fromresultintent(data);             view parentlayout = findviewbyid(android.r.id.content);              // signed in             if (resultcode == result_ok) {                 final firebaseuser signeduser = mauth.getcurrentuser();                 valueeventlistener valueeventlistener = new valueeventlistener() {                     @override                     public void ondatachange(datasnapshot datasnapshot) {                         if (!datasnapshot.child(getstring(r.string.users)).child(signeduser.getuid()).exists()) {                             log.d("signinprocess", "ondatachange: **register");                             uid = setnulltodefaultvalue(signeduser.getuid());                             email = setnulltodefaultvalue(signeduser.getemail());                             user muser = new user();                             muser.setuid(uid);                             muser.setemail(email);                             map<string, object> usermap = muser.usertomap();                             usermap.put("date", calendar.getinstance().gettime().tostring());                             mdatabase.child(getstring(r.string.users)).child(mauth.getcurrentuser().getuid()).updatechildren(usermap).addoncompletelistener(new oncompletelistener<void>() {                                 @override                                 public void oncomplete(@nonnull task<void> task) {                                     startactivity(new intent(mainactivity.this, chooseusernameactivity.class));                                     finish();                                 }                             });                         } else {                             log.d("signinprocess", "ondatachange: **log in");                         }                     }                      @override                     public void oncancelled(databaseerror databaseerror) {                      }                 };                 mdatabase.addvalueeventlistener(valueeventlistener);                 snackbar.make(parentlayout, "you signed in!", snackbar.length_long);                 startactivity(new intent(mainactivity.this, mainactivity.class));                 finish();                 return;             } else {                 // sign in failed                 if (response == null) {                     // user pressed button                     snackbar.make(parentlayout, "user presses back", snackbar.length_long);                     return;                 }                  if (response.geterrorcode() == errorcodes.no_network) {                     snackbar.make(parentlayout, "no network", snackbar.length_long);                     return;                 }                  if (response.geterrorcode() == errorcodes.unknown_error) {                     snackbar.make(parentlayout, "unknown error", snackbar.length_long);                     return;                 }             }          }     }      @override     public void onbackpressed() {         drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);         if (drawer.isdraweropen(gravitycompat.start)) {             drawer.closedrawer(gravitycompat.start);         } else {             super.onbackpressed();         }     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_log_out) {             authui.getinstance()                     .signout(mainactivity.this)                     .addoncompletelistener(new oncompletelistener<void>() {                         @override                         public void oncomplete(@nonnull task<void> task) {                             mauth = firebaseauth.getinstance();                             firebaseuser currentuser = mauth.getcurrentuser();                             if (currentuser == null) {                                 signuser();                             }                         }                     });             return true;         }          return super.onoptionsitemselected(item);     }      private void signuser() {         startactivityforresult(                 authui.getinstance()                         .createsigninintentbuilder()                         .settheme(r.style.darktheme) //                            .setlogo(r.mipmap.ic_launcher)                         .setissmartlockenabled(true)                         .setavailableproviders(                                 arrays.aslist(                                         new authui.idpconfig.builder(authui.email_provider).build(),                                         new authui.idpconfig.builder(authui.phone_verification_provider).build()                                 ))                         .build(),                 rc_sign_in);     }      @suppresswarnings("statementwithemptybody")     @override     public boolean onnavigationitemselected(menuitem item) {         // handle navigation view item clicks here.         int id = item.getitemid();          if (id == r.id.nav_home) {             startactivity(new intent(mainactivity.this, mainactivity.class));             return true;         } else if (id == r.id.nav_profile) {             startactivity(new intent(mainactivity.this, profileactivity.class));             return true;         } else if (id == r.id.nav_settings) {             startactivity(new intent(mainactivity.this, settingsactivity.class));             return true;         }         drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);         drawer.closedrawer(gravitycompat.start);         return true;     }      //database housekeeping     public string setnulltodefaultvalue(string s) {         string defaultvalue = "default_value";         if (s == null)             return defaultvalue;         return s;     } } 

and here model class use gethouse_name() method:

/**  * created nikos on 22/7/2017.  */  public class houses {     private string availability;     private string city;     private string country;     private string description;     private object fotos;     private string hid;     private string house_name;     private string langitude;     private string longitude;     private string mainfoto;     private string max_people;     private string price;     private string rating;     private string postalcode;     //services     private string aircondition;     private string balcony;     private string breakfast;     private string cafe_bar_restaurant;     private string child_keeping;     private string clothes_laundry;     private string conference_rooms;     private string dinner;     private string doctor_support;     private string elevator;     private string hair_dryer;     private string in_room_safebox;     private string iron_ironing_board;     private string minibar;     private string newspaper_delivery;     private string parking;     private string private_bath;     private string reception_24;     private string room_service;     private string soundproof_walls;     private string wifi;     private string uid;     private object user_reviews;      public houses() {     }      public houses(string availability, string city, string country, string description, object fotos, string hid, string house_name, string langitude, string longitude, string mainfoto, string max_people, string price, string rating, string postalcode, string aircondition, string balcony, string breakfast, string cafe_bar_restaurant, string child_keeping, string clothes_laundry, string conference_rooms, string dinner, string doctor_support, string elevator, string hair_dryer, string in_room_safebox, string iron_ironing_board, string minibar, string newspaper_delivery, string parking, string private_bath, string reception_24, string room_service, string soundproof_walls, string wifi, string uid, object user_reviews) {         this.availability = availability;         this.city = city;         this.country = country;         this.description = description;         this.fotos = fotos;         this.hid = hid;         this.house_name = house_name;         this.langitude = langitude;         this.longitude = longitude;         this.mainfoto = mainfoto;         this.max_people = max_people;         this.price = price;         this.rating = rating;         this.aircondition = aircondition;         this.balcony = balcony;         this.breakfast = breakfast;         this.cafe_bar_restaurant = cafe_bar_restaurant;         this.child_keeping = child_keeping;         this.clothes_laundry = clothes_laundry;         this.conference_rooms = conference_rooms;         this.dinner = dinner;         this.doctor_support = doctor_support;         this.elevator = elevator;         this.hair_dryer = hair_dryer;         this.in_room_safebox = in_room_safebox;         this.iron_ironing_board = iron_ironing_board;         this.minibar = minibar;         this.newspaper_delivery = newspaper_delivery;         this.parking = parking;         this.private_bath = private_bath;         this.reception_24 = reception_24;         this.room_service = room_service;         this.soundproof_walls = soundproof_walls;         this.wifi = wifi;         this.uid = uid;         this.user_reviews = user_reviews;         this.postalcode = postalcode;     }      public void setpostalcode(string postalcode) {         this.postalcode = postalcode;     }      public string getpostalcode() {         return postalcode;     }      public void setavailability(string availability) {         this.availability = availability;     }      public void setcity(string city) {         this.city = city;     }      public void setcountry(string country) {         this.country = country;     }      public void setdescription(string description) {         this.description = description;     }      public void setfotos(object fotos) {         this.fotos = fotos;     }      public void sethid(string hid) {         this.hid = hid;     }      public void sethouse_name(string house_name) {         this.house_name = house_name;     }      public void setlangitude(string langitude) {         this.langitude = langitude;     }      public void setlongitude(string longitude) {         this.longitude = longitude;     }      public void setmainfoto(string mainfoto) {         this.mainfoto = mainfoto;     }      public void setmax_people(string max_people) {         this.max_people = max_people;     }      public void setprice(string price) {         this.price = price;     }      public void setrating(string rating) {         this.rating = rating;     }      public void setaircondition(string aircondition) {         this.aircondition = aircondition;     }      public void setbalcony(string balcony) {         this.balcony = balcony;     }      public void setbreakfast(string breakfast) {         this.breakfast = breakfast;     }      public void setcafe_bar_restaurant(string cafe_bar_restaurant) {         this.cafe_bar_restaurant = cafe_bar_restaurant;     }      public void setchild_keeping(string child_keeping) {         this.child_keeping = child_keeping;     }      public void setclothes_laundry(string clothes_laundry) {         this.clothes_laundry = clothes_laundry;     }      public void setconference_rooms(string conference_rooms) {         this.conference_rooms = conference_rooms;     }      public void setdinner(string dinner) {         this.dinner = dinner;     }      public void setdoctor_support(string doctor_support) {         this.doctor_support = doctor_support;     }      public void setelevator(string elevator) {         this.elevator = elevator;     }      public void sethair_dryer(string hair_dryer) {         this.hair_dryer = hair_dryer;     }      public void setin_room_safebox(string in_room_safebox) {         this.in_room_safebox = in_room_safebox;     }      public void setiron_ironing_board(string iron_ironing_board) {         this.iron_ironing_board = iron_ironing_board;     }      public void setminibar(string minibar) {         this.minibar = minibar;     }      public void setnewspaper_delivery(string newspaper_delivery) {         this.newspaper_delivery = newspaper_delivery;     }      public void setparking(string parking) {         this.parking = parking;     }      public void setprivate_bath(string private_bath) {         this.private_bath = private_bath;     }      public void setreception_24(string reception_24) {         this.reception_24 = reception_24;     }      public void setroom_service(string room_service) {         this.room_service = room_service;     }      public void setsoundproof_walls(string soundproof_walls) {         this.soundproof_walls = soundproof_walls;     }      public void setwifi(string wifi) {         this.wifi = wifi;     }      public void setuid(string uid) {         this.uid = uid;     }      public void setuser_reviews(object user_reviews) {         this.user_reviews = user_reviews;     }      public string getavailability() {         return availability;     }      public string getcity() {         return city;     }      public string getcountry() {         return country;     }      public string getdescription() {         return description;     }      public object getfotos() {         return fotos;     }      public string gethid() {         return hid;     }      public string gethouse_name() {         return house_name;     }      public string getlangitude() {         return langitude;     }      public string getlongitude() {         return longitude;     }      public string getmainfoto() {         return mainfoto;     }      public string getmax_people() {         return max_people;     }      public string getprice() {         return price;     }      public string getrating() {         return rating;     }      public string getaircondition() {         return aircondition;     }      public string getbalcony() {         return balcony;     }      public string getbreakfast() {         return breakfast;     }      public string getcafe_bar_restaurant() {         return cafe_bar_restaurant;     }      public string getchild_keeping() {         return child_keeping;     }      public string getclothes_laundry() {         return clothes_laundry;     }      public string getconference_rooms() {         return conference_rooms;     }      public string getdinner() {         return dinner;     }      public string getdoctor_support() {         return doctor_support;     }      public string getelevator() {         return elevator;     }      public string gethair_dryer() {         return hair_dryer;     }      public string getin_room_safebox() {         return in_room_safebox;     }      public string getiron_ironing_board() {         return iron_ironing_board;     }      public string getminibar() {         return minibar;     }      public string getnewspaper_delivery() {         return newspaper_delivery;     }      public string getparking() {         return parking;     }      public string getprivate_bath() {         return private_bath;     }      public string getreception_24() {         return reception_24;     }      public string getroom_service() {         return room_service;     }      public string getsoundproof_walls() {         return soundproof_walls;     }      public string getwifi() {         return wifi;     }      public string getuid() {         return uid;     }      public object getuser_reviews() {         return user_reviews;     }      @override     public string tostring() {         return "houses{" +                 "availability='" + availability + '\'' +                 ", city='" + city + '\'' +                 ", country='" + country + '\'' +                 ", description='" + description + '\'' +                 ", fotos=" + fotos +                 ", hid='" + hid + '\'' +                 ", house_name='" + house_name + '\'' +                 ", langitude='" + langitude + '\'' +                 ", longitude='" + longitude + '\'' +                 ", mainfoto='" + mainfoto + '\'' +                 ", max_people='" + max_people + '\'' +                 ", price='" + price + '\'' +                 ", rating='" + rating + '\'' +                 ", postalcode='" + postalcode + '\'' +                 ", aircondition='" + aircondition + '\'' +                 ", balcony='" + balcony + '\'' +                 ", breakfast='" + breakfast + '\'' +                 ", cafe_bar_restaurant='" + cafe_bar_restaurant + '\'' +                 ", child_keeping='" + child_keeping + '\'' +                 ", clothes_laundry='" + clothes_laundry + '\'' +                 ", conference_rooms='" + conference_rooms + '\'' +                 ", dinner='" + dinner + '\'' +                 ", doctor_support='" + doctor_support + '\'' +                 ", elevator='" + elevator + '\'' +                 ", hair_dryer='" + hair_dryer + '\'' +                 ", in_room_safebox='" + in_room_safebox + '\'' +                 ", iron_ironing_board='" + iron_ironing_board + '\'' +                 ", minibar='" + minibar + '\'' +                 ", newspaper_delivery='" + newspaper_delivery + '\'' +                 ", parking='" + parking + '\'' +                 ", private_bath='" + private_bath + '\'' +                 ", reception_24='" + reception_24 + '\'' +                 ", room_service='" + room_service + '\'' +                 ", soundproof_walls='" + soundproof_walls + '\'' +                 ", wifi='" + wifi + '\'' +                 ", uid='" + uid + '\'' +                 ", user_reviews=" + user_reviews +                 '}';     }      @exclude     public map<string, object> tomap() {         hashmap<string, object> houseobject = new hashmap<>();          houseobject.put("city", city);         houseobject.put("country", country);         houseobject.put("description", description);         houseobject.put("fotos", fotos);         houseobject.put("hid", hid);         houseobject.put("house_name", house_name);         houseobject.put("langitude", langitude);         houseobject.put("longitude", longitude);         houseobject.put("mainfoto", mainfoto);         houseobject.put("max_people", max_people);         houseobject.put("price", price);         houseobject.put("rating", rating);         houseobject.put("postalcode", postalcode);         houseobject.put("aircondition", aircondition);         houseobject.put("balcony", balcony);         houseobject.put("breakfast", breakfast);         houseobject.put("cafe_bar_restaurant", cafe_bar_restaurant);         houseobject.put("child_keeping", child_keeping);         houseobject.put("clothes_laundry", clothes_laundry);         houseobject.put("conference_rooms", conference_rooms);         houseobject.put("dinner", dinner);         houseobject.put("doctor_support", doctor_support);         houseobject.put("elevator", elevator);         houseobject.put("hair_dryer", hair_dryer);         houseobject.put("in_room_safebox", in_room_safebox);         houseobject.put("iron_ironing_board", iron_ironing_board);         houseobject.put("minibar", minibar);         houseobject.put("newspaper_delivery", newspaper_delivery);         houseobject.put("parking", parking);         houseobject.put("private_bath", private_bath);         houseobject.put("reception_24", reception_24);         houseobject.put("room_service", room_service);         houseobject.put("soundproof_walls", soundproof_walls);         houseobject.put("wifi", wifi);         houseobject.put("uid", uid);         houseobject.put("user_reviews", user_reviews);          return houseobject;     } } 

try use code

databasereference mdatabase;   mdatabase = firebasedatabase.getinstance().getreference(); mdatabase.child("houses").addchildeventlistener(new childeventlistener() {             @override             public void onchildadded(datasnapshot datasnapshot, string s) {                   map<string, string> map = (map<string, string>) datasnapshot.getvalue();                  houses model = new houses(map.get("key_name"), map.get("key_name"),......);                  adapter.additem(model);                 progressdialog.dismiss();             }              @override             public void onchildchanged(datasnapshot datasnapshot, string s) {              }              @override             public void onchildremoved(datasnapshot datasnapshot) {              }              @override             public void onchildmoved(datasnapshot datasnapshot, string s) {              }              @override             public void oncancelled(databaseerror databaseerror) {                 progressdialog.dismiss();                 toast.maketext(fetchdata.this, "something went wrong -> " + databaseerror, toast.length_long).show();             }         }); 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -