android - java.lang.IllegalStateException:找不到所需的视图 - 黄油刀有时不工作
问题描述
如果有时想在一个月后发布它,我会遇到异常。每次我必须删除构建文件夹并且错误消失。因此,长期保持这种状态是有风险的,因为有时开发人员可能会忘记检查此活动是否打开。
到目前为止,奇怪的是它只发生在一个文件 ProductListActivity.kt
此运行时错误看起来像常见错误是否需要 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.access$800(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 的日志中看到,因此您可以用视图绑定替换您的代码(而不是黄油刀)(出现错误的区域)
推荐阅读
- azure - 存储资源管理器未列出 Cosmos DB 文档
- xamarin.forms - Xamarin 表单:Gif 图像不适用于 UWP 中的 FFimageloading
- postman - 在邮递员支付集成中的请求正文中发送 URL
- python - 根据熊猫中的某些特定条件拆分字符串
- angular - 角度:net::ERR_EMPTY_RESPONSE
- ember.js - 如何排除公用文件夹中的图像文件
- jquery - 表单提交失败后显示隐藏字段
- django - python3 不是用于创建 django runserver 的内部或外部命令、可运行程序或批处理文件
- python - 如何解决此错误“对象没有属性”
- google-chrome - WebdriverIO - 由于 chrome/chromedriver 错误,无法运行测试运行程序