在适配平板和手机布局时,经常会创建几种不同的布局。完了运行时butterknife会报空指针,用死方法一个个抓到最后才指向
Caused by: java.lang.IllegalStateException: Required view 'ivGoodListStyle' with ID 2131690022 for field 'ivGoodListStyle' and method 'setOnClick' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
at butterknife.internal.Utils.findRequiredView(Utils.java:92)
at org.chuangpai.e.shop.mvp.ui.activity.GoodsListActivity_ViewBinding.<init>(GoodsListActivity_ViewBinding.java:103)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at butterknife.ButterKnife.createBinding(ButterKnife.java:199)
at butterknife.ButterKnife.bind(ButterKnife.java:124)
at org.chuangpai.e.shop.mvp.ui.activity.GoodsListActivity.onCreate(GoodsListActivity.java:1023)
at android.app.Activity.performCreate(Activity.java:6980)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at cn.jiguang.a.a.d.a.a.d.callActivityOnCreate(Unknown Source:24)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
这个错误,原因是适配时两个xml布局控件不一致导致。不管是 layout 还是large layout,都必须一致,不然就会报空