0
votes

I have the following code:

activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".Main2Activity">

    <android.support.design.widget.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        app:menu="@menu/nav_items" />

</RelativeLayout>

Main2Activity:

package asus.example.com.oop;

import android.os.Bundle; import android.app.Activity;

public class Main2Activity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

}

nav_items.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:icon="@drawable/home24"
        android:title="@string/home"
        />

    <item
        android:icon="@drawable/notifications24"
        android:title="@string/notifications"
        />

    <item
        android:icon="@drawable/person24"
        android:title="@string/account"
        />
</menu>

And when I run the program I have the following error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{asus.example.com.oop/asus.example.com.oop.Main2Activity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class android.support.design.widget.BottomNavigationView Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class android.support.design.widget.BottomNavigationView Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.design.widget.BottomNavigationView Caused by: java.lang.reflect.InvocationTargetException

I don't know, why i have this problem. I added line compile 'com.android.support:design' to build gradle, but it still doesn't work. What's the matter?

1
Try extends AppCompatActivity if you want to use support classes - OneCricketeer
Use same version of appcompat library and design support library in your app - Gaurav

1 Answers

0
votes

To use AppCompat features your activity needs to be extending AppCompatActivity

replace

public class Main2Activity extends Activity

with

public class Main2Activity extends AppCompatActivity