Butter Knife - Unable to bind views for Fragment

24,708

Solution 1

have a look on this answer Using Butter Knife in Custom BaseAdapter SubClass Results in "Unable to inject views" error

looks like you must mistake on some view type or id

Solution 2

Duplicate answer. Anyway my problem (and probably yours too) is:

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    />

Then the ImageView is bound to another class, for example an ImageButton

@Bind(R.id.imageView)
ImageButton notAnImageButton

Solution 3

This error happens because of wrong data type of bind view

Share:
24,708
Mufaddal Gulshan
Author by

Mufaddal Gulshan

Updated on December 27, 2020

Comments

  • Mufaddal Gulshan
    Mufaddal Gulshan over 3 years

    I get an exception java.lang.RuntimeException: Unable to bind views for Fragment on ButterKnife.bind(this, view). The code is as shown below:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_personal, container, false);
    
        ButterKnife.bind(this, view);
    
        BindData();
    
        return view;
    }
    
    • pelotasplus
      pelotasplus almost 9 years
      please show us whole fragment that you are using ButterKnife with and also exact, whole, runtime exception you get.
    • gmemario
      gmemario almost 9 years
      I use just like this and have no problem, something is missing. Show us the exception and what BindData() is doing.
    • patel135
      patel135 about 7 years
      ButterKnife.bind(getActivity(), view); just replace this line with yours
  • Mufaddal Gulshan
    Mufaddal Gulshan almost 9 years
    Thank you, i rechecked my code and apparently the mistake was with the view type