FirebaseRecycleAdapter UncaughtException

时间:2017-04-10 12:31:15

标签: android firebase firebase-realtime-database firebaseui

我使用FirebaseRecycleAdapter填充评论系统:

CommentViewHolder.class:

public class CommentViewHolder extends RecyclerView.ViewHolder {

TextView displayNameView;
TextView bodyView;
String uid;

CommentViewHolder(View itemView) {
    super(itemView);
    displayNameView = (TextView) itemView.findViewById(R.id.comment_displayName);
    bodyView = (TextView) itemView.findViewById(R.id.comment_body);
}

public void setDisplayName(String displayName) {
    displayNameView.setText(displayName);
}

public void setBody(String body) {
    bodyView.setText(body);
}

public void setUid(String uid) {
    this.uid = uid;
}
}

在我的活动中:

mCommentsRecycler = (RecyclerView) findViewById(R.id.recycler_comments);
mCommentsRecycler.setHasFixedSize(false);
mCommentsRecycler.setLayoutManager(new LinearLayoutManager(this));
mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.comment_item, CommentViewHolder.class, CommentsReference) {
@Override
protected void populateViewHolder(CommentViewHolder viewHolder, final Comment model, int position) {
viewHolder.setDisplayName(model.getDisplayName());
viewHolder.setBody(model.getBody());
viewHolder.setUid(model.getUid());
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
     @Override
      public void onClick(View v) {
          showCommentClickedList(model);
       }
    });
 }
};
mCommentsRecycler.setAdapter(mAdapter);

我尝试将ViewHolder放在活动中,使用&#34; public static&#34;就像我在一些答案中看到的那样,但同样的错误,

最有线的部分 - 当我从ANDROID STUDIO运行时,它工作得很完美,一旦我创建调试apk或发布apk问题就会开始

错误:

04-10 15:13:16.137 22024-22024/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: PID: 22024
java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]
   at com.firebase.ui.database.FirebaseRecyclerAdapter.onCreateViewHolder(FirebaseRecyclerAdapter.java:171)
   at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6319)
   at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5507)
   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5392)
   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5388)

FirebaseRecyclerAdapter.onCreateViewHolder(FirebaseRecyclerAdapter.java:171)Constructor<VH> constructor = mViewHolderClass.getConstructor(View.class);

1 个答案:

答案 0 :(得分:0)

如果您在FirebaseRecyclerAdapter内宣布了ViewHolder,那么它应该是publicstatic

在两种情况下,在FirebaseRecyclerAdapter内或在其自己的类中声明,构造函数必须为public