java.lang.IllegalStateException:找不到所需的视图-黄油刀有时不起作用

时间:2019-08-27 09:54:09

标签: android kotlin butterknife

如果有时想到在一个月后发布该异常,我将跟踪异常。每次我必须删除构建文件夹,错误都会消失。因此,长时间保持这种状态是有风险的,因为有时开发人员可能会忘记检查此活动是否打开。

到目前为止,很奇怪的是,它只发生在一个文件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

1 个答案:

答案 0 :(得分:1)

我从日志中看到的是您正在使用kotlin,因此可以代替黄油刀,而将代码替换为视图绑定(出现错误的区域)