android - Recycler View crashing in the app (Firebase) -
i building simple blog app using firebase. when login login page enter main activity contains toolbar , recycler view . when enter activity app crashes every single time showing error in firebaserecycleradapter .
the following code:
package com.example.adi.blogger; import android.content.context; import android.content.intent; import android.support.annotation.nonnull; import android.support.v7.app.actionbar; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.support.v7.widget.linearlayoutmanager; import android.support.v7.widget.recyclerview; import android.support.v7.widget.toolbar; import android.util.log; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.imageview; import android.widget.textview; import android.widget.toast; import com.firebase.ui.database.firebaserecycleradapter; import com.google.firebase.auth.firebaseauth; import com.google.firebase.auth.firebaseuser; 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 com.squareup.picasso.callback; import com.squareup.picasso.networkpolicy; import com.squareup.picasso.picasso; import org.w3c.dom.text; import static android.r.attr.checkboxpreferencestyle; import static android.r.attr.description; import static android.icu.lang.ucharacter.graphemeclusterbreak.l; import static android.icu.lang.ucharacter.graphemeclusterbreak.t; import static android.transition.fade.in; public class mainactivity extends appcompatactivity { firebaseauth mauth; firebaseauth.authstatelistener mlistener; recyclerview cardrecyclerview; databasereference mainactivitydatabasereference; databasereference mdatabaseuser; string log_tag ="boo"; toolbar mytoolbar; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mainactivitydatabasereference = firebasedatabase.getinstance().getreference().child("blog_data"); mainactivitydatabasereference.keepsynced(true); log.e(log_tag,"you under kep sync method"); mytoolbar = (toolbar)findviewbyid(r.id.toolbar); setsupportactionbar(mytoolbar); cardrecyclerview = (recyclerview)findviewbyid(r.id.blogrecyclerview); cardrecyclerview.setlayoutmanager(new linearlayoutmanager(this)); log.e(log_tag,"you under setlayout manager in oncreate"); mdatabaseuser = firebasedatabase.getinstance().getreference().child("user"); mauth = firebaseauth.getinstance(); //mainactivitydatabasereference = firebasedatabase.getinstance().getreference().child("blog_data"); mlistener = new firebaseauth.authstatelistener() { @override public void onauthstatechanged(@nonnull firebaseauth firebaseauth) { firebaseuser muser = firebaseauth.getcurrentuser(); log.e(log_tag,"you entering auth state listener"); if(muser==null){ intent getbackintent = new intent(mainactivity.this,loginactivity.class); getbackintent.addflags(intent.flag_activity_clear_top); startactivity(getbackintent); } log.e(log_tag,"you coming out of now"); } }; } @override public boolean oncreateoptionsmenu(menu menu) { log.e(log_tag,"you in on create option menu"); getmenuinflater().inflate(r.menu.menu_xml,menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { switch(item.getitemid()){ case r.id.addbuttontoolbar: intent newblogintent = new intent(this,addblog.class); startactivity(newblogintent); break; case r.id.signoutbuttontoolbar: mauth.signout(); intent signout_intent = new intent(mainactivity.this,loginactivity.class); signout_intent.addflags(intent.flag_activity_clear_top); startactivity(signout_intent); break; } return true; } @override protected void onstart() { log.e(log_tag,"you in onstart method"); toast.maketext(this,"making onstart",toast.length_short).show(); super.onstart(); mauth.addauthstatelistener(mlistener); checkuserexist(); log.e(log_tag,"you before creating firebase adapter"); firebaserecycleradapter<bloggs,recyclerblogview> firebaserecycleradapter = new firebaserecycleradapter<bloggs, recyclerblogview>( bloggs.class, r.layout.blog_row, recyclerblogview.class, mainactivitydatabasereference) { @override protected void populateviewholder(recyclerblogview viewholder, bloggs model, int position) { log.e(log_tag,"in populate view"); toast.maketext(getapplicationcontext(),"you entering populate view holder method",toast.length_short).show(); viewholder.settitle(model.gettitle()); viewholder.setdescription(model.getdescription()); viewholder.setimageurl(getapplicationcontext(),model.getimageurl()); } }; cardrecyclerview.setadapter(firebaserecycleradapter); firebaserecycleradapter.notifydatasetchanged(); } public class recyclerblogview extends recyclerview.viewholder { view mview; recyclerblogview(view itemview) { super(itemview); log.e(log_tag,"you in recyclerblogview class"); mview = itemview; } public void settitle(string title){ textview recylertitle = (textview)mview.findviewbyid(r.id.cardtitle); recylertitle.settext(title); } public void setdescription(string description){ textview recyclerconten = (textview)mview.findviewbyid(r.id.carddescription); recyclerconten.settext(description); } public void setimageurl(final context ctx, final string imageurl){ final imageview blogimage = (imageview)findviewbyid(r.id.blogimagecard); picasso.with(ctx).load(imageurl).networkpolicy(networkpolicy.offline).into(blogimage, new callback() { @override public void onsuccess() { } @override public void onerror() { picasso.with(ctx).load(imageurl).centercrop().into(blogimage); } }); } } private void checkuserexist() { system.out.print("check user entered"); toast.maketext(getapplicationcontext(),"you entering check user exist method",toast.length_short).show(); log.e(log_tag,"check user exist method"); final string user_id = mauth.getcurrentuser().getuid(); mdatabaseuser.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { if(!datasnapshot.haschild(user_id)){ intent accountsetupintent = new intent(mainactivity.this,accountsetup.class); accountsetupintent.addflags(intent.flag_activity_clear_top); startactivity(accountsetupintent); } } @override public void oncancelled(databaseerror databaseerror) { } }); } }
the following logcat description
04-07 01:48:53.439 7820-7820/? e/androidruntime: fatal exception: main process: com.example.adi.blogger, pid: 7820 java.lang.runtimeexception: java.lang.nosuchmethodexception: <init> [class android.view.view] @ com.firebase.ui.database.firebaserecycleradapter.oncreateviewholder(firebaserecycleradapter.java:172) @ android.support.v7.widget.recyclerview$adapter.createviewholder(recyclerview.java:6290) @ android.support.v7.widget.recyclerview$recycler.trygetviewholderforpositionbydeadline(recyclerview.java:5478) @ android.support.v7.widget.recyclerview$recycler.getviewforposition(recyclerview.java:5363) @ android.support.v7.widget.recyclerview$recycler.getviewforposition(recyclerview.java:5359) @ android.support.v7.widget.linearlayoutmanager$layoutstate.next(linearlayoutmanager.java:2141) @ android.support.v7.widget.linearlayoutmanager.layoutchunk(linearlayoutmanager.java:1525) @ android.support.v7.widget.linearlayoutmanager.fill(linearlayoutmanager.java:1488) @ android.support.v7.widget.linearlayoutmanager.onlayoutchildren(linearlayoutmanager.java:585) @ android.support.v7.widget.recyclerview.dispatchlayoutstep2(recyclerview.java:3506) @ android.support.v7.widget.recyclerview.onmeasure(recyclerview.java:2969) @ android.view.view.measure(view.java:18811) @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:716) @ android.widget.relativelayout.onmeasure(relativelayout.java:462) @ android.view.view.measure(view.java:18811) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5952) @ android.widget.framelayout.onmeasure(framelayout.java:194) @ android.support.v7.widget.contentframelayout.onmeasure(contentframelayout.java:139) @ android.view.view.measure(view.java:18811) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5952) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1465) @ android.widget.linearlayout.measurevertical(linearlayout.java:748) @ android.widget.linearlayout.onmeasure(linearlayout.java:630) @ android.view.view.measure(view.java:18811) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5952) @ android.widget.framelayout.onmeasure(framelayout.java:194) @ android.view.view.measure(view.java:18811) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5952) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1465) @ android.widget.linearlayout.measurevertical(linearlayout.java:748) @ android.widget.linearlayout.onmeasure(linearlayout.java:630) @ android.view.view.measure(view.java:18811) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5952) @ android.widget.framelayout.onmeasure(framelayout.java:194) @ com.android.internal.policy.phonewindow$decorview.onmeasure(phonewindow.java:2643) @ android.view.view.measure(view.java:18811) @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:2127) @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1243) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1479) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1134) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:6045) @ android.view.choreographer$callbackrecord.run(choreographer.java:860) @ android.view.choreographer.docallbacks(choreographer.java:672) @ android.view.choreographer.doframe(choreographer.java:608) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:846) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5441) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:738) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:628) caused by: java.lang.nosuchmethodexception: <init> [class android.view.view] @ java.lang.class.getconstructor(class.java:528) @ java.lang.class.getconstruct 04-07 01:48:53.469 7820-7820/? i/process: sending signal. pid: 7820 sig: 9
since you've put recyclerblogview
inside class, need mark static
. so:
public static class recyclerblogview extends recyclerview.viewholder {
also see github issue: https://github.com/firebase/firebaseui-android/issues/210
Comments
Post a Comment