When using Butterknife for Android development, it is found that inject, such as tvinfo, is always null.
@InjectView (r.id.textview1info) TextView tvinfo; @Overridepublic void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); GetWindow (). Requestfeature (Window.feature_no_title); Setcontentview ( R.layout.main); Butterknife.inject (this); Tvinfo.settext ("test");//Tvinfo is null.}
Later on the official network to find a solution, as follows:
Http://jakewharton.github.io/butterknife/ide-eclipse.html
Eclipse Configuration
Right click to your project in the package Explorer. Head to Java compiler→annotation processing and check "Enable Project specific Settings".
Ensure the other annotation processing settings is the same as shown below:
Expand the Annotation processing section and select Factory Path. Check "Enable Project specific Settings" and then click "Add JARs ...". Navigate to the project ' s libs/
folder and select the Butter knife jar.
- Click "OK" to save the new settings. Eclipse would ask you to rebuild your project to which you should click "Yes"
- Make sure, the
.apt_generated/
folder is in your project root. It should contain files like YOURACTIVITY$$ViewInjector.java
. If These files is not present trigger a clean build by selected Project→clean. This folder and files should not being checked into revision control.
- Lastly, under "Java Compiler", make sure, the Compiler compliance level are set to Java version 1 .6 at minimum.
The solution to using butterknife cannot inject view