The import butterknife.InjectView cannot be resolved

一曲冷凌霜 提交于 2019-11-29 03:30:26

问题


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.


回答1:


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




回答2:


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.




回答3:


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




回答4:


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




回答5:


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



来源:https://stackoverflow.com/questions/31531475/the-import-butterknife-injectview-cannot-be-resolved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!