13

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

import butterknife.InjectView;

并且在MainActivity.javaandVerticalLinearRecyclerViewSample.java中,每次出现@InjectView(...)注释时,我都会收到以下错误:

InjectView cannot be resolved to a type

那么我该怎么办呢?


我尝试了什么:

我见过这个问题。对我不起作用,在那里发表评论。

在步骤#3 之前,我已按照这些步骤包含黄油刀库。关于第 4 步,“确保 .apt_generated/ 文件夹位于您的项目根目录中......” - 该项目没有任何命名文件夹.apt-generated或项目根文件夹中的任何内容。


注意:我实际使用的是 Eclipse,而且 Github 上的项目是针对 Android Studio 的,所以我在 eclipse 中创建了一个新项目,并从下载的 Android Studio 项目中复制了各个文件。我希望这不会产生影响。

4

5 回答 5

32

感谢@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.
...

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

于 2015-07-21T14:52:57.693 回答
8

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

于 2015-07-21T23:57:13.957 回答
7

@InjectView不再可用并由 代替@BindView。我们必须导入Butterknife依赖项才能使用annotations.

于 2018-04-24T10:31:53.967 回答
5

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

于 2018-03-26T07:08:06.220 回答
0

尝试添加:implementation 'com.jakewharton:butterknife:6.1.0'在您的build.gradle

于 2018-05-18T16:31:58.167 回答