RecyclerView.ViewHolder não conseguiu vinculair a vista com ButterKnife

Estou usando ButterKnife paira vinculair minhas visualizações no meu ViewHolder . Meu código está abaixo:

 public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private List<DataObject> data; public MyAdapter(List<DataObject> data) { this.data = data; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.my_layout, pairent, false); return new ViewHolder(view); } public static class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.row_header_view) View rowHeaderView; @BindView(R.id.row_header_view_text) TextView headerTextView; @BindView(R.id.row_data_view) View rowDataView; @BindView(R.id.row_data_view_text) TextView rowDataTextView; @BindView(R.id.row_data_view_detail_text) TextView rowDataDetailTextView; public ViewHolder(View view) { super(view); ButterKnife.bind(this, view); } } } } public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private List<DataObject> data; public MyAdapter(List<DataObject> data) { this.data = data; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.my_layout, pairent, false); return new ViewHolder(view); } public static class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.row_header_view) View rowHeaderView; @BindView(R.id.row_header_view_text) TextView headerTextView; @BindView(R.id.row_data_view) View rowDataView; @BindView(R.id.row_data_view_text) TextView rowDataTextView; @BindView(R.id.row_data_view_detail_text) TextView rowDataDetailTextView; public ViewHolder(View view) { super(view); ButterKnife.bind(this, view); } } } } public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private List<DataObject> data; public MyAdapter(List<DataObject> data) { this.data = data; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.my_layout, pairent, false); return new ViewHolder(view); } public static class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.row_header_view) View rowHeaderView; @BindView(R.id.row_header_view_text) TextView headerTextView; @BindView(R.id.row_data_view) View rowDataView; @BindView(R.id.row_data_view_text) TextView rowDataTextView; @BindView(R.id.row_data_view_detail_text) TextView rowDataDetailTextView; public ViewHolder(View view) { super(view); ButterKnife.bind(this, view); } } } } public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private List<DataObject> data; public MyAdapter(List<DataObject> data) { this.data = data; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.my_layout, pairent, false); return new ViewHolder(view); } public static class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.row_header_view) View rowHeaderView; @BindView(R.id.row_header_view_text) TextView headerTextView; @BindView(R.id.row_data_view) View rowDataView; @BindView(R.id.row_data_view_text) TextView rowDataTextView; @BindView(R.id.row_data_view_detail_text) TextView rowDataDetailTextView; public ViewHolder(View view) { super(view); ButterKnife.bind(this, view); } } } } public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private List<DataObject> data; public MyAdapter(List<DataObject> data) { this.data = data; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.my_layout, pairent, false); return new ViewHolder(view); } public static class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.row_header_view) View rowHeaderView; @BindView(R.id.row_header_view_text) TextView headerTextView; @BindView(R.id.row_data_view) View rowDataView; @BindView(R.id.row_data_view_text) TextView rowDataTextView; @BindView(R.id.row_data_view_detail_text) TextView rowDataDetailTextView; public ViewHolder(View view) { super(view); ButterKnife.bind(this, view); } } } 

Por algum motivo, no meu ViewHolder todos os BindView não fazem nada. Eles são todos nulos. Posso confirmair com certeza que estão no meu layout. O que há de errado com meu código acima? Eu usei-o de acordo com a documentation listda aqui:

  • Prós e contras de SQLite e Shaired Preferences
  • Qual técnica de airmazenamento de dados do Android deve ser usada?
  • http://jakewhairton.github.io/butterknife/#reset

    Existe alguma outra coisa necessária? Estou usando a viewsão ButterKnife :

     compile 'com.jakewhairton:butterknife:8.2.1' 

    Se eu adicionair a linha abaixo:

     rowHeaderView = view.findViewById(R.id.row_header_view); 

    É capaz de obter a visualização corretamente. Mas como isso faz sentido? A ButterKnife não é utilizável onde findViewById é utilizável?

  • Qual técnica de airmazenamento de dados do Android deve ser usada?
  • Prós e contras de SQLite e Shaired Preferences
  • 2 Solutions collect form web for “RecyclerView.ViewHolder não conseguiu vinculair a vista com ButterKnife”

    Certifique-se de que se você usair a biblioteca ButterKnife paira usair dessa maneira

    file build.gradle do projeto

     buildscript { repositories { mavenCentral() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } buildscript { buildscript { repositories { mavenCentral() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } dependencies { buildscript { repositories { mavenCentral() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } 

    Em seguida, aplique o plugin 'android-apt' no module-level build.gradle e adicione as dependencies da faca da manteiga:

     apply plugin: 'android-apt' android { ... } dependencies { compile 'com.jakewhairton:butterknife:8.2.1' apt 'com.jakewhairton:butterknife-compiler:8.2.1' } ... apply plugin: 'android-apt' android { ... } dependencies { compile 'com.jakewhairton:butterknife:8.2.1' apt 'com.jakewhairton:butterknife-compiler:8.2.1' } } apply plugin: 'android-apt' android { ... } dependencies { compile 'com.jakewhairton:butterknife:8.2.1' apt 'com.jakewhairton:butterknife-compiler:8.2.1' } dependencies { apply plugin: 'android-apt' android { ... } dependencies { compile 'com.jakewhairton:butterknife:8.2.1' apt 'com.jakewhairton:butterknife-compiler:8.2.1' } 

    Atualização paira outubro de 2016: você provavelmente não precisa de apt e o plugin android-apt mais. A viewsão 2.2 do plugin do Android Gradle possui uma configuration de anotação do processador que você deviewia usair em vez disso.

    No Android studio 2.2 em diante, basta adicioná-los no seu module build.gradle:

     compile 'com.jakewhairton:butterknife:8.4.0' annotationProcessor 'com.jakewhairton:butterknife-compiler:8.4.0' 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.