首页 > 代码库 > 使用ButterKnife无法inject view的解决办法
使用ButterKnife无法inject view的解决办法
使用ButterKnife做android开发时,发现无法inject,如下,tvInfo总是null。
@InjectView(R.id.textView1Info) TextView tvInfo; @Override public 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. }
后来在官网上找到解决办法,如下:
http://jakewharton.github.io/butterknife/ide-eclipse.html
Eclipse Configuration
Right click on your project in the Package Explorer. Head to Java Compiler → Annotation Processing and check "Enable project specific settings".
Ensure the other annotation processing settings are 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 will ask you to rebuild your project to which you should click "Yes"
- Make sure that the
.apt_generated/
folder is in your project root. It should contain files likeYOURACTIVITY$$ViewInjector.java
. If these files are not present trigger a clean build by selected Project → Clean. This folder and files should not be checked into revision control. - Lastly, under "Java Compiler", make sure that the Compiler compliance level is set to Java version 1.6 at minimum.
使用ButterKnife无法inject view的解决办法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。