Closed jp1017 closed 7 years ago
在baseActvivity的oncreate方法中,ButterKnife.bind(this);应该在initData方法前执行
是啊,initData就在他后面
......
mUnbinder = ButterKnife.bind(this);
ComponentInject();//依赖注入
initData();
建议你按两下shift,看下有没有 (acivity名)$$ViewBinder.java 这个类,看下里面找到id没,这框架我们公司几个项目都在用,一直没出现过你说的问题
@JessYanCoding 刚看了下,build下确实没有黄油刀产生的东西,,只有dagger2产生的。。真是冲突了吗?
http://www.jianshu.com/p/268c14130bea
按照上面的文章修改后,build下有黄油刀生成的资源了,还是空指针。。。还会哪里不对呢
@JessYanCoding 解决了,就是上面的解决方案 :smile:
@jp1017 那个文章并没有说butterknife怎么配置的啊
@pangff 官网有,和上面的一样 使用annotationProcessor, 官网,看官网,没错!
@jp1017 我两都用的annotationProcessor,但是编译会出错 annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
annotationProcessor
要AS 2.2+
@jp1017 classpath 'com.android.tools.build:gradle:2.2.2' compile 'com.google.dagger:dagger:2.2' annotationProcessor 'com.google.dagger:dagger-compiler:2.2' compile 'com.jakewharton:butterknife:8.4.0' annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
和引号没有关系,这样还是不行
具体报啥错呢,,,
compile 'com.google.dagger:dagger:2.2' apt 'com.google.dagger:dagger-compiler:2.2' compile 'com.jakewharton:butterknife:8.4.0' apt 'com.jakewharton:butterknife-compiler:8.4.0'
嗯,butterknife在library和app配置有些不一样,具体看他官网
@jp1017 换了dagger版本到2.8可以了。非常感谢
我也有这个问题,测试好久了还没解决,跟demo里的配置来的,demo就没问题,我的就有问题,不知道咋回事
@jp1017 请问你是怎么解决的,我看了下我有生成viewbinding,里面也有id,但还是不行
请问您遇到过吗?我测试了一上午了,,
只有一个TextView
然后在
initData()
方法里设置内容 mTextView.setText("你好");`就报 mTextView 空指针了,不用黄油刀,findViewbyId 正常。
也有说两者冲突,https://github.com/JakeWharton/butterknife/issues/803
然而并。。没解决。。。
我的工程和你的项目对比了,都一样,,我的不行,你的完美运行,好尴尬,,,求破啊