1

I'm developing and android app, everything worked perfect, then i had a simple code, tested and error free, then when i try to test the app, my mainscreen Activity start throwing the following 3 errors:

Caused by: android.view.InflateException: Binary XML file line #53: Error inflating class android.support.design.widget.FloatingActionButton

Caused by: java.lang.reflect.InvocationTargetException

Caused by: java.lang.IllegalAccessError: tried to access class android.support.v7.widget.AppCompatImageHelper from class android.support.design.widget.FloatingActionButton

The all three errors at the same time and in the same line(setContentView(R.layout.activity_main_screen);) in ActivityMainScreen.java onCreate(), The thing is that the code i had was in a way different activity, who isn't even related to the main one, so i don't know what could it be, hope you can help, here is the code of the error:

activity_main_screen.xml:

<RelativeLayout
    android:id="@+id/Container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff">

    <RelativeLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="false"
        android:layout_alignParentEnd="true"
        android:background="#fff"
        android:paddingTop="50dp"></RelativeLayout>
    <android.support.design.widget.AppBarLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/appbarlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="2dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="50dp"
            app:elevation="2dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:background="@color/primary_dark_material_dark"
            android:layout_above="@+id/content_frame"
            android:layout_alignParentStart="true">

            <ImageButton
                android:id="@+id/Sort"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@drawable/ic_action_filter"
                android:background="@color/transparent"
                android:layout_gravity="right"
                android:layout_marginEnd="10dp"/>

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_alignParentBottom="true"
        android:layout_marginEnd="15dp"
        android:layout_marginBottom="15dp"
        android:src="@drawable/ic_add_white_24dp"
        app:fabSize="normal"
        app:backgroundTint="@color/colorPrimary"
        android:layout_alignParentEnd="true" />
</RelativeLayout>

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#111"/>

MainScreenActivity.java:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getApplicationContext());
        setContentView(R.layout.activity_main_screen);

        tagTitles = getResources().getStringArray(R.array.navigation_array);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawerList = (ListView) findViewById(R.id.left_drawer);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.bringToFront();
        fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.bringToFront();

        Sort = (ImageView) findViewById(R.id.Sort);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainScreenActivity.this,CreateWorkout.class);
                startActivityForResult(i,1);
            }
        });

        ArrayList<DrawerItem> items = new ArrayList<DrawerItem>();
        items.add(new DrawerItem(tagTitles[0],R.mipmap.home));
        items.add(new DrawerItem(tagTitles[1],R.mipmap.acrobatics));
        items.add(new DrawerItem(tagTitles[2],R.mipmap.profile));

        drawerList.setAdapter(new DrawerListAdapter(this, items));
        drawerList.setOnItemClickListener(new DrawerItemClickListener());

        // Crear ActionBarDrawerToggle para la apertura y cierre
//        drawerToggle.setDrawerIndicatorEnabled(false);
        toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
        toolbar.setTitle("Home");
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (drawerLayout.isDrawerOpen(drawerList)){
                    drawerLayout.closeDrawer(drawerList);
                }
                else
                    drawerLayout.openDrawer(drawerList);
            }
        });

        if (savedInstanceState == null) {
            selectItem(0);
        }

        Sort.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new MaterialDialog.Builder(MainScreenActivity.this)
                        .title(R.string.filtertitle)
                        .items(R.array.filter_items)
                        .itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() {
                            @Override
                            public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                                android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
                                if (which != -1){
                                    Fragment currentFragment = fragmentManager.findFragmentById(R.id.content_frame);
                                    if (currentFragment instanceof MainFragment) {
                                        ((MainFragment) currentFragment).Task(text.toString());
                                        //place your filtering logic here using currentFragment
                                    }
                                }
                                return true;
                            }
                        })
                        .positiveText(R.string.choose)
                        .show();
            }
        });
    }
Andres Rodriguez
  • 209
  • 1
  • 6
  • 13
  • Check out the answer provided here: [InflateException with FloatingActionButton from Official Design Library](http://stackoverflow.com/a/30895974/2077405). It worked for me. – Ugo Nov 19 '16 at 22:06

0 Answers0