Butterknife: App crash when use <fragment ... />view inside XML

Created on 14 Aug 2016  路  6Comments  路  Source: JakeWharton/butterknife

Using Android Studio 2.2 Beta and ButterKnife 8.2.1

I have a MainActivity file which contain a in its layout file. This load a Fragment but when i use ButterKnife.bind() in its onCreateView method i always got this error

android.view.InflateException: Binary XML file line #81: Error inflating class fragment

In case i used the rootView.findViewById method everything is ok.

Needs Info

Most helpful comment

Just for future reference.

Caused by: java.lang.ClassCastException: android.support.v7.widget.RecyclerView cannot be cast to android.widget.AdapterView

That exception is triggered when you use the notation @OnItemSelected(R.id.recycler_view_tip_records) using a RecyclerView. The notation need an AdapterView object (ListView).

@OnItemSelected(R.id.recycler_view_tip_records)
public void onItemClick(int position){
        Toast.makeText(getActivity().getApplicationContext(), "Item selected at position " + position, Toast.LENGTH_SHORT).show();
    }

All 6 comments

Paste the full exception

The full exception is here @JakeWharton

What makes you think Butter Knife is at fault here?

Caused by: java.lang.ClassCastException: android.support.v7.widget.RecyclerView cannot be cast to android.widget.AdapterView

You're trying to bind a RecyclerView to an AdapterView.

Just for future reference.

Caused by: java.lang.ClassCastException: android.support.v7.widget.RecyclerView cannot be cast to android.widget.AdapterView

That exception is triggered when you use the notation @OnItemSelected(R.id.recycler_view_tip_records) using a RecyclerView. The notation need an AdapterView object (ListView).

@OnItemSelected(R.id.recycler_view_tip_records)
public void onItemClick(int position){
        Toast.makeText(getActivity().getApplicationContext(), "Item selected at position " + position, Toast.LENGTH_SHORT).show();
    }

Or @OnItemClick from ListView
@OnItemClick(R.id.list_view) public void onCameraSelected(View view, int position) { }

Was this page helpful?
0 / 5 - 0 ratings