java.lang.illegalStateException: Butterknife

10,463

Solution 1

It is possible if your TabItem is not ready, so try to use this while declaring variable and its respective onclick.

Taken reference from here

 @Nullable
 @BindView(R.id.l)TabItem tabItem;

 @Optional
 @OnClick(R.id.l)
  void check(){
     //method logic...
  }

Solution 2

I had similar error, it was due to wrong layout file was being inflated on the view which didnt have the field in question that was being reported in error.

Solution 3

In my case this error was because I was using two layouts for different versions:

  • activity_login.xml

  • activity_login.xml (v21)

I added a progressBar in activity_login.xml but...

I forgot to added to activity_login.xml (v21).

Share:
10,463
mdadil2019
Author by

mdadil2019

Trying to become professional android developer

Updated on June 26, 2022

Comments

  • mdadil2019
    mdadil2019 about 2 years

    I am using butterknife to bind my views so when the activity start, the following exception is thrown

    java.lang.RuntimeException: Unable to start activity ComponentInfo{..package name...}: java.lang.IllegalStateException: Required view 'l' with ID 2131558524 for field 'tabItem' and method 'check' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.

    Note: I have called Butterknife.bind(this) after setContentView(view) and this view is not optional

    My Code

    public class HandlingActivity extends AppCompatActivity {
    
    @BindView(R.id.container_view)FrameLayout container;
    @BindView(R.id.l)TabItem tabItem;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_handling);
        ButterKnife.bind(this);
    }
    
    @OnClick(R.id.l)void check(){
        StoriesFragment storiesFragment = new StoriesFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.container_view,storiesFragment).commit();
         }
    }