pRaNaY
pRaNaY

Reputation: 25320

Unable to bind views for .. $RecyclerViewHolders at ButterKnife.bind(this, itemView); in RecyclerViewHolders

I am getting below error log:

java.lang.RuntimeException: Unable to bind views for .. $RecyclerViewHolders at butterknife.ButterKnife.bind(ButterKnife.java:322) at butterknife.ButterKnife.bind(ButterKnife.java:279) ... at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)

public class RecyclerViewHolders extends RecyclerView.ViewHolder implements View.OnClickListener {

    private Context mContext;


    @Bind(R.id.tvRowServiceCenterName)
    CustomTextView tvRowServiceCenterName;
    @Bind(R.id.tvRowServiceCenterKmsValue)
    CustomTextView tvRowServiceCenterKmsValue;

    @Bind(R.id.ivRowServiceCenterImage)
    CircleImageView ivRowServiceCenterImage;
    @Bind(R.id.ivRowServiceCenterStatus)
    CircleImageView ivRowServiceCenterStatus;

    public RecyclerViewHolders(Context context, View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView); // Getting error here at runtime
        this.mContext = context;
        //itemView.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {

    }
}

I am also referring Butterknife is unable to bind inside my Adapter Class

Also see ButterKnife.bind(this, itemView); related issue.

But it can't helps me. Am I missing something, or doing something wrongly?

Upvotes: 0

Views: 985

Answers (1)

Riten
Riten

Reputation: 2949

You can try below code:

public static class ViewHolder extends RecyclerView.ViewHolder{
@Bind(R.id.tvRowServiceCenterName)
CustomTextView tvRowServiceCenterName;
@Bind(R.id.tvRowServiceCenterKmsValue)
CustomTextView tvRowServiceCenterKmsValue;
@Bind(R.id.ivRowServiceCenterImage)
CircleImageView ivRowServiceCenterImage;
@Bind(R.id.ivRowServiceCenterStatus)
CircleImageView ivRowServiceCenterStatus;

private ViewHolder(View view, int viewType, Context context){
        super(view);
        ButterKnife.bind(this, view);
    }
}

Upvotes: 3

Related Questions