java.lang.IllegalStateException:未找到所需的视图 - butterknife 有时不工作
java.lang.IllegalStateException: Required view not found - butterknife not working sometimes
如果有时想在一个月后发布它,我会遇到异常。每次我必须删除构建文件夹时,错误就会消失。因此,长时间 运行 保持这种状态是有风险的,因为有时开发人员可能会忘记检查此 activity 是否打开。
到目前为止,奇怪的是它只发生在一个文件中 ProductListActivity.kt
这个 运行time 错误看起来像常见错误是否需要 Gradle 配置来修复它。
如何彻底摆脱它?
java.lang.RuntimeException: Unable to start activity ComponentInfo ProductDetails.activity.ProductListActivity}: java.lang.IllegalStateException: Required view 'name_text_box' with ID 2131362920 for method 'onNearbyClicked' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access0(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalStateException: Required view 'name_text_box' with ID 2131362920 for method 'onNearbyClicked' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
at butterknife.internal.Utils.findRequiredView(Utils.java:88)
at ProductDetails.activity.ProductListActivity_ViewBinding.<init>(ProductListActivity_ViewBinding.java:27)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at butterknife.ButterKnife.bind(ButterKnife.java:170)
at butterknife.ButterKnife.bind(ButterKnife.java:99)
at common.BaseActivity.setContentView(BaseActivity.java:51)
at ProductDetails.activity.ProductListActivity.onCreate(ProductListActivity.kt:220)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at and
我从日志中看到您正在使用 kotlin,因此您可以用视图绑定(出现错误的区域)替换您的代码而不是 butterknife
如果有时想在一个月后发布它,我会遇到异常。每次我必须删除构建文件夹时,错误就会消失。因此,长时间 运行 保持这种状态是有风险的,因为有时开发人员可能会忘记检查此 activity 是否打开。
到目前为止,奇怪的是它只发生在一个文件中 ProductListActivity.kt
这个 运行time 错误看起来像常见错误是否需要 Gradle 配置来修复它。
如何彻底摆脱它?
java.lang.RuntimeException: Unable to start activity ComponentInfo ProductDetails.activity.ProductListActivity}: java.lang.IllegalStateException: Required view 'name_text_box' with ID 2131362920 for method 'onNearbyClicked' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access0(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalStateException: Required view 'name_text_box' with ID 2131362920 for method 'onNearbyClicked' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
at butterknife.internal.Utils.findRequiredView(Utils.java:88)
at ProductDetails.activity.ProductListActivity_ViewBinding.<init>(ProductListActivity_ViewBinding.java:27)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at butterknife.ButterKnife.bind(ButterKnife.java:170)
at butterknife.ButterKnife.bind(ButterKnife.java:99)
at common.BaseActivity.setContentView(BaseActivity.java:51)
at ProductDetails.activity.ProductListActivity.onCreate(ProductListActivity.kt:220)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at and
我从日志中看到您正在使用 kotlin,因此您可以用视图绑定(出现错误的区域)替换您的代码而不是 butterknife