FirebaseUI-Android: NoSuchMethodException while using FirebaseRecyclerAdapter
I am using this library to show data in RecyclerView
using FirebaseRecyclerAdapter
. But app is crashing with the NoSuchMethodException
.
My code is:
mAdapter = new FirebaseRecyclerAdapter<TaskModel, TaskViewHolder>(TaskModel.class, R.layout.task_list_item, TaskViewHolder.class, firebase) {
@Override
protected void populateViewHolder(TaskViewHolder viewHolder, TaskModel model, int position) {
Log.i("HOME", "populateViewHolder called");
}
};
mRecyclerView.setAdapter(mAdapter);
View Helper class:
class TaskViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView mTimeTv;
private TextView mTimeAmPm;
private TextView mTaskTitleTv;
private void findViews(View v) {
mTimeTv = (TextView) v.findViewById(R.id.time_tv);
mTimeAmPm = (TextView) v.findViewById(R.id.time_am_pm);
mTaskTitleTv = (TextView) v.findViewById(R.id.task_title_tv);
}
public TaskViewHolder(View itemView) {
super(itemView);
findViews(itemView);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
}
}
Please correct me if i am doing something wrong.
java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]
at com.firebase.ui.FirebaseRecyclerAdapter.onCreateViewHolder(FirebaseRecyclerAdapter.java:168)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5228)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4453)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2900)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:584)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1037)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:747)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:761)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1983)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:17
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 42 (7 by maintainers)
There are two likely causes for this:
TaskViewHolder
class ispublic
TaskViewHolder
is an inner class of e.g. your activity, make sure it’sstatic
So likely
pro-guard still caused crash… adding
@Keep
to the ViewHolder class solved for me…@SUPERCILEX , yea I saw that recommendation on Stack Overflow posts and had that in my proguard file, but it didn’t seem to make a difference.
I just moved my viewholder to a separate package/class rather than having it be an inner class. Then in my proguard file, I added
-keep class com.mypackage.myapp.viewholders.** { *; }
Based on this Stack Overflow post, that move seemed to work for folks. I’ve uploaded my new apk to the store, so I’m just waiting for Google to refresh things before I test it.
Thanks for checking in @SUPERCILEX
Guys, problem solved after add public to MyViewHolder constructor. http://stackoverflow.com/questions/39594346/firebaserecycleradapter-give-nosuchmethodexception-if-build-using-release-keysto
It’s strange the problem only exist in release build configuration.
Yes @plugie, proguard is disabled when minifyEnabled is set to false. As @samtstern said, move your class into a separate file/package and then ignore that package name in the the proguard rules file. My proguard and Firebase are working fine with my current setup of the proguard-rules.pro file. Below’s what’s currently in it. Also, unless you’re using Eventbus, omit the Eventbus code.
`-keepclassmembers class com.test.finalapp.Models.** { ;} -keep class com.test.finalapp.Viewholders.* { *; }
-keep class com.firebase.* { ; } -keep class org.apache.* { ; } -keepnames class com.fasterxml.jackson.* { ; } -keepnames class javax.servlet.* { ; } -keepnames class org.ietf.jgss.* { ; } -dontwarn org.w3c.dom. -dontwarn org.joda.time.** -dontwarn org.shaded.apache.** -dontwarn org.ietf.jgss.** -keepattributes Signature -keepattributes Annotation
//Eventbus code below: -keepclassmembers class ** { @org.greenrobot.eventbus.Subscribe <methods>; } -keep enum org.greenrobot.eventbus.ThreadMode { *; }
//Only required if you use AsyncExecutor -keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent { <init>(java.lang.Throwable); }`
@SUPERCILEX , thanks. My app works fine when I install it onto my phone via USB. But these Firebase errors only happen when I install it via the Play Store. So when I said/say “update”, I mean that I make changes to my app and the proguard file. Then I have to update the Play Store apk to then see if the errors still happen. No matter whether I do “Build APK” or “Generate signed APK”, I’ll still be uploading the new APK file to the Play Store 😕
I’ve learned a TON today with this thread and my /r/androiddev Reddit post 😃 👍
thank god , one day behind submission of Graduation Project
thank you guys
Number 2 😃
Note that these types of questions are typically better addressed on StackOverflow, where more people see them.