Search code examples
androidkotlinbutterknife

java.lang.IllegalStateException: Required view not found - butterknife not working sometimes


I'm getting following exception if sometimes thought of posting it after a month. Every time I have to delete build folder and error goes away. So it is risky to stay like this condition for long run, as sometimes developer might forget to check this activity is opening or not.

So far strangely it is only happening with one file ProductListActivity.kt

This runtime error looks like common error Is there a Gradle configurations needed to fix it.

How to completely get rid of it?

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

Solution

  • What i can see from the logs that you are using kotlin, so instead of butterknife you can replace your code with view binding(area which are getting error)