13

I am trying to use this library project, so I tried to run the sample application (in /app/source/main/ in the Github link), and in MainActivity.java, I am getting the error on the import

import butterknife.InjectView;

and also in MainActivity.java and VerticalLinearRecyclerViewSample.java, at every occurance of @InjectView(...) annotation, I get the following error:

InjectView cannot be resolved to a type

So what should I do about this?


WHAT I TRIED:

I have seen this question. Didn't work for me, left a comment there.

I have followed these steps to include the Butter Knife library till Step#3. About Step#4, "Make sure that the .apt_generated/ folder is in your project root..." - this project does not have any folder named .apt-generated or something in the project root folder.


Note: I actually use Eclipse, and the project on Github is for Android Studio, so I created a new project in eclipse and copied individual files from the downloaded Android Studio project. I hope this does not made a difference.

Community
  • 1
  • 1
Solace
  • 8,612
  • 22
  • 95
  • 183
  • 3
    Which version of ButterKnife you are using? Latest version has bind instead of InjectView. Version before that, uses ButterKnife.inject(this) to inject view. Also, Eclipse is not supported anymore, start using Android Studio. – Sharjeel Jul 21 '15 at 06:10
  • @Sharj v7.0.1 downloaded from this page. `@Bind` works, thank you so very much. If you can post it as an answer, I can accept it. – Solace Jul 21 '15 at 06:23

5 Answers5

32

Credit to @Sharj for answering first.

The Butterknife 7.0.0 release included the breaking change of renaming of the annotation 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

Derek
  • 1,572
  • 1
  • 14
  • 25
  • poor Object oriented...changing the annotation breaks app if done a automated build – anshulkatta Dec 23 '16 at 09:58
  • Late response here, but the change in API was done as part of the 7.x.x Major release so it is allowed under semantic versioning. http://semver.org/ – Derek Jun 08 '17 at 09:03
8

Latest version has bind instead of InjectView. Version before that, uses ButterKnife.inject(this) to inject view. Also, Eclipse is not supported anymore, start using Android Studio.

Sharjeel
  • 15,588
  • 14
  • 58
  • 89
  • 2
    Hi, I really wanted to accept your answer. But the answer by Derek (in which they have accredited your answer) is more descriptive and slightly more comprehensive. So I asked a question on meta stack exchange about which one to accept, and got the advice that I should accept the one which will be more helpful to the community. So I could only upvote your answer. I would upvote more if I could. Thank you for answering. – Solace Jul 22 '15 at 01:52
  • Hey. Im still working on Eclipse. Is there any way of importing ButterKnife on there? – Zen Jun 22 '16 at 12:11
7

@InjectView is no more available and is replaced by @BindView. We will have to import Butterknife dependencies to use the annotations.

4b0
  • 21,981
  • 30
  • 95
  • 142
Manideep
  • 353
  • 3
  • 13
5

Change ButterKnife.inject(this); to ButterKnife.bind(this);

paulfranco
  • 84
  • 1
  • 3
0

Try add:implementation 'com.jakewharton:butterknife:6.1.0' in your build.gradle

Youn Tivoli
  • 230
  • 2
  • 13