Butter Knife
是jakewharton 大神写的基于Android开发的依赖注入库。
最近使用发现老是报Nullporinter的错误。
Butter Knife 官网研究后才知道,使用依赖注入需要给java编译器导入java。
解决Butter Knife 空指针问题:
-
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.