-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quoting Butter Knife 8.8.1 in the library, using BindView in the app module, but the view appears NullPointerException #1127
Comments
Turn on debug logging on the |
Thanks @JakeWharton reply.
My app module in
A supplemental information, my project has three layers:
I do not know if it is affected by this structure. |
I encountered the same problem,user gradle:3.0.0 and butterknife 8.8.1;
@qinxianyuzou 兄弟你这个问题解决了吗,我升级到3.0遇到这个问题,很烦 |
@imaiya 并没有,其实有个简单的解决办法,直接把butterknife挂在app module里面,而不在library里挂,这样就不会出现问题,不过这么搞不符合组件开发而已。不仅仅是在studio3.0,在2.3的时候用butterknife挂在library里也是会这样的,所以我不懂是不是配置没有配置正确还是butterknife有bug
|
@qinxianyuzou 对啊,我这边是有基础library,在library的基类中bind(this),在app具体页面中使用bindview,之前使用7.x是没有问题的,但是因为升级3.0需要使用8.x,升级之后就报空了;如果单独拎出来会破坏基础库的机构,不是很想这样做,如果找到好的解决方案callback一下哈 |
我的项目更加复杂,项目架构是主管架构的,一个基础library库,然后一个基类library库,最后才是app的一层依赖一层,我不知道是不是这个原因导致了butterknife失效了,如果是,那就麻烦了
|
@JakeWharton I am getting the same error in android studio 3.0.0 and butterknife 8.8.1
|
@qinxianyuzou @imaiya Try adding 'annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'' to the module |
@wvisible Is it added to the app module instead of added to the library? |
@qinxianyuzou yes,you can try it. |
@wvisible @qinxianyuzou Thank you for the suggestion that I used this method to solve the problem |
@wvisible You're right, this method can solve the problem, but doing so is tantamount to direct the butter knife on the app module Nothing to do with the library, which is not in line with the idea I put the butter knife into the Library.I hope that the library is perfect and independent, not every time need to add in the app module |
在defaultConfig中加入 |
you can add
in app module build.gradle too. |
@wimvogt Yes, I know this, but it does not solve the problem of using a butterknife in a library.
|
I deleted apply plugin: 'com.jakewharton.butterknife' and It worked |
did anyone find a solution? I am facing the same problem in gradle:3.0.0 |
use gradle:3.0.0 and butterknife 8.8.1; |
I had no problem after change to Android Studio 3.0, However after change part of code to -> "kotlin". Build has no problem but after run the app. need a help. |
@BansookNam are you using I had the same issue when introducing Kotlin - you need to use |
@kassim Thank you kassim |
@qinxianyuzou I have the same problem. I don't know if you've solved the problem now |
@shenwenbin123 No, at the moment I can only solve the problem by loading butterknife into the application module. |
@qinxianyuzou 这个不是 bug ,因为 butterknife 的工作机制是:利用 annotationProcessor 来生成 XXX_ViewBinding 类的,对应的 XXX 里面的 View 的初始化是在 XXX_ViewBinding 内完成的。 @Nullable @CheckResult @UiThread
private static Constructor<? extends Unbinder> findBindingConstructorForClass(Class<?> cls) {
Constructor<? extends Unbinder> bindingCtor = BINDINGS.get(cls);
if (bindingCtor != null) {
if (debug) Log.d(TAG, "HIT: Cached in binding map.");
return bindingCtor;
}
String clsName = cls.getName();
if (clsName.startsWith("android.") || clsName.startsWith("java.")) {
if (debug) Log.d(TAG, "MISS: Reached framework class. Abandoning search.");
return null;
}
try {
Class<?> bindingClass = Class.forName(clsName + "_ViewBinding");
//noinspection unchecked
bindingCtor = (Constructor<? extends Unbinder>) bindingClass.getConstructor(cls, View.class);
if (debug) Log.d(TAG, "HIT: Loaded binding class and constructor.");
} catch (ClassNotFoundException e) {
if (debug) Log.d(TAG, "Not found. Trying superclass " + cls.getSuperclass().getName());
bindingCtor = findBindingConstructorForClass(cls.getSuperclass());
} catch (NoSuchMethodException e) {
throw new RuntimeException("Unable to find binding constructor for " + clsName, e);
}
BINDINGS.put(cls, bindingCtor);
return bindingCtor;
} 个人见解,轻喷 |
@qinxianyuzou 大神,问题解决没?我无意间看到其他大神在library里面引用butterknife,首先在project的gradle文件里面的buildscript下面用butterknife作者提供的插件dependencies { |
must add |
Thank you @gmm932 Your suggestion works (probably missed that part from README file) App level configuration:
Project level configuration:
|
@qinxianyuzou 最后有搞定吗?在lib中引入黄油刀,在app module中使用 |
My App also had this problem, this was because I used Glide 4.0 in my app. I could not find viewbinging.class from build/generated/source. For updaeing Glide to 4.0 version, I add code: |
同样的问题 gradle4.1 tools:3.1.0, 跑不起来 |
有解决的么 lib的build放入依赖 ,,app放注解,也报错 |
按着 README.md 里的方法配置就可以了。 |
@wangkunlin 最后default加了一段代码 还用7.0.1解决,这个框架不建议在项目中用,不如base里抽个findview'byid兼容性好 |
//used in kotlin //used in java i thought kapt also can used in java, ai yousang |
I used a butterknife 8.8.1 in AndroidStudio3.0。
My project gradle:
In my app module gradle:
In my Library module gradle:
In my app module activity binding View, @ BindView (R.id.xx) and @BindView (R2.id.xx) have tried, but still NullPointerException.Why is that?
My English is relatively poor, the above text from the Google translation, grammar unreasonable please understand
The text was updated successfully, but these errors were encountered: