Java – Annotations @InjectView not working after importing Butterknife in Android Studio?

Annotations @InjectView not working after importing Butterknife in Android Studio?… here is a solution to the problem.

Annotations @InjectView not working after importing Butterknife in Android Studio?

Recently introduced to butterknife. I added this line to my gradle(module:app) file:
Compile ‘com.jakewharton:butterknife:7.0.1’

It syncs without any errors. I could put “butterknife. Butterknife” into the class file I usually import. But cant import butterknife. InjectView doesn’t seem to have? Any suggestions?

Solution

Butterknife version 7.0.0 contains breaking changes to rename comment verbs. This is highlighted in the changelog and reflected in the website.

Version 7.0.0 *(2015-06-27)*
----------------------------

* `@Bind` replaces `@InjectView` and `@InjectViews`.
 * `ButterKnife.bind` and `ButterKnife.unbind` replaces `ButterKnife.inject` 
    and `ButterKnife.reset`, respectively.
...

https://github.com/JakeWharton/butterknife/blob/f65dc849d80f6761d1b4a475626c568b2de883d9/CHANGELOG.md

A very good and up-to-date introduction to usage is located http://jakewharton.github.io/butterknife/.

This is the simplest usage:

class ExampleActivity extends Activity {
  @Bind(R.id.title) TextView title;
  @Bind(R.id.subtitle) TextView subtitle;
  @Bind(R.id.footer) TextView footer;

@Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_activity);
    ButterKnife.bind(this);
     TODO Use fields...
  }
}

Related Problems and Solutions