导入butterknife.InjectView无法解析

Sol*_*ace 12 eclipse android butterknife

我正在尝试使用这个库项目,所以我尝试运行示例应用程序(在/app/source/main/Github链接中),然后MainActivity.java,我在导入时收到错误

import butterknife.InjectView;
Run Code Online (Sandbox Code Playgroud)

而且在MainActivity.javaVerticalLinearRecyclerViewSample.java,在每一次出现@InjectView(...)注解,我得到以下错误:

InjectView cannot be resolved to a type
Run Code Online (Sandbox Code Playgroud)

那我该怎么办呢?


我做了什么:

我见过这个问题.没有为我工作,在那里留下了评论.

按照这些步骤将Butter Knife库包括在第3步之前.关于步骤#4,"确保.apt_generated /文件夹位于项目根目录..." - 此项目没有任何文件夹.apt-generated或项目根文件夹中的内容.


注意:我实际上使用Eclipse,而Github上的项目是针对Android Studio的,因此我在eclipse中创建了一个新项目,并从下载的Android Studio项目中复制了单个文件.我希望这没有任何区别.

Der*_*rek 31

感谢@Sharj首先回答.

Butterknife 7.0.0版本包括重命名注释动词的重大变化.这在更改日志中突出显示并反映在网站中.

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

 * `@Bind` replaces `@InjectView` and `@InjectViews`.
 * `ButterKnife.bind` and `ButterKnife.unbind` replaces `ButterKnife.inject` 
    and `ButterKnife.reset`, respectively.
...
Run Code Online (Sandbox Code Playgroud)

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


Sha*_*arj 8

最新版本bind而不是InjectView.之前的版本,用于ButterKnife.inject(this)注入视图.此外,Eclipse不再受支持,开始使用Android Studio.

  • 嗨,我真的很想接受你的回答.但是Derek的答案(他们已经认可了你的答案)更具描述性,而且更加全面.所以我问了一个关于元堆栈交换的问题,关于哪一个接受,并得到了我应该接受对社区更有帮助的建议.所以我只能提出你的答案.如果可以的话,我会更多地投票.谢谢你的回答. (2认同)

小智 6

@InjectView不再可用,取而代之的是@BindView.我们将不得不导入Butterknife依赖项来使用annotations.


小智 5

更改 ButterKnife.inject(this); 到 ButterKnife.bind(this);