android - Firebase Database Exception -
this question has answer here:
- android save object in firebase 1 answer
here class intend read location type data item firebase database , store in location type object. tried store datasnapshot in object of class had location type argument in constructor, got same error saying :
" com.google.firebase.database.databaseexception: class android.location.location missing constructor no arguments"
package com.example.aadi.sarthi_; import android.content.context; import android.content.intent; import android.location.location; 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.util.log; import android.view.layoutinflater; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import com.google.firebase.database.childeventlistener; import com.google.firebase.database.datasnapshot; import com.google.firebase.database.databaseerror; import com.google.firebase.database.databasereference; import com.google.firebase.database.firebasedatabase; import com.google.firebase.database.valueeventlistener; import java.util.arraylist; import java.util.list; public class activenotifications extends fragment{ public static final string notification_msg = "notification msg"; public recyclerview recyclerview; string user_mac; public list<notifylistrowitem> result; public useradapter useradapter; private databasereference reference = firebasedatabase.getinstance().getreference(); private databasereference eventref = reference.child("events"); // create intent send notification public static intent makenotificationintent(context context, string msg) { intent intent = new intent( context, activenotifications.class ); intent.putextra( notification_msg, msg ); return intent; } @nullable @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) { view view = inflater.inflate(r.layout.activity_active_notifications, container, false); getmac(); result = new arraylist<>(); recyclerview = (recyclerview) view.findviewbyid(r.id.notification_list); recyclerview.sethasfixedsize(true); linearlayoutmanager rlm = new linearlayoutmanager(getactivity()); rlm.setorientation(linearlayoutmanager.vertical); recyclerview.setlayoutmanager(rlm); /* createnotifylistrowitem();*/ useradapter = new useradapter(result); recyclerview.setadapter(useradapter); updatelist(); return view; } @override public boolean oncontextitemselected(menuitem item) { switch (item.getitemid()){ case 0: break; case 1: break; } return super.oncontextitemselected(item); } public void updatelist(){ final databasereference locationref = reference.child(string.valueof(user_mac)).child("location"); final location userloc = null; final location eventloc = null; locationref.addlistenerforsinglevalueevent(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { if(datasnapshot.exists()) { location location = datasnapshot.getvalue(location.class); userloc.set(location); } } @override public void oncancelled(databaseerror databaseerror) { } }); eventref.limittofirst(2).addchildeventlistener(new childeventlistener() { @override public void onchildadded(datasnapshot datasnapshot, string s) { eventref.push().child("location"); location location = datasnapshot.getvalue(location.class); eventloc.set(location); if(eventloc.distanceto(userloc)<=1000) { result.add(datasnapshot.getvalue(notifylistrowitem.class)); useradapter.notifydatasetchanged(); } } @override public void onchildchanged(datasnapshot datasnapshot, string s) { log.w("asd", "in onchildchanged"); notifylistrowitem notifylistrowitem = datasnapshot.getvalue(notifylistrowitem.class); int index = getitemindex(notifylistrowitem); result.set(index,notifylistrowitem); useradapter.notifyitemchanged(index); } @override public void onchildremoved(datasnapshot datasnapshot) { log.w("in ", "onchildremoved"); notifylistrowitem model = datasnapshot.getvalue(notifylistrowitem.class); int index = getitemindex(model); result.remove(index); useradapter.notifyitemremoved(index); } @override public void onchildmoved(datasnapshot datasnapshot, string s) { log.w("in", "onchildmoved"); } @override public void oncancelled(databaseerror databaseerror) { log.w("in", "onchildcancelled"); return; } }); } private int getitemindex(notifylistrowitem item){ int index = -1; (int i=0;i<result.size();i++){ if(result.get(i).key.equals(item.key)){ index = i; break; } } return index; } protected void getmac(){ gettingmac gettingmac = new gettingmac(getactivity()); user_mac = gettingmac.mac(); } }
you need have empty constructor location class.
public location () {}
Comments
Post a Comment