Boboyobo
Boboyobo

Reputation: 11

Didn't find class "android.view.menu"

I have been getting the following problem:

Caused by: android.view.InflateException: Binary XML file line #13: Binary XML file line #2: Error inflating class menu Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class menu Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.menu" on path: DexPathList[[zip file "/data/app/com.cpsc4150.glovebox-xjT3LiC43G5FDyD3dDmxuw==/base.apk"],nativeLibraryDirectories=[/data/app/com.cpsc4150.glovebox-xjT3LiC43G5FDyD3dDmxuw==/lib/x86, /system/lib]]

I have tried cleaning the build, deleting build files and having android studio remake them ect. No f which seem to work.

My menu file is in res/menu/menu.xml and is the only thing located there.

MainActivity

@Override
    public boolean onCreateOptionsMenu(Menu menu){
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }


    /**
     * <p>Defines the actions to be taken when the menu activity is created</p>
     * @param savedInstanceState a saved instance of the menu activity id one exist
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        int REQUEST_ALL = 1;
        String[] PERMISSIONS = {
                android.Manifest.permission.WAKE_LOCK,
                android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
                android.Manifest.permission.ACCESS_FINE_LOCATION,
                android.Manifest.permission.ACCESS_COARSE_LOCATION,
                android.Manifest.permission.CAMERA
        };

        if (hasPermissions(this, PERMISSIONS) == false) {
            ActivityCompat.requestPermissions(this, PERMISSIONS, REQUEST_ALL);
        }

        serviceList = loadServices(SERVICE_LIST_ID);
        if (serviceList == null) serviceList = new ArrayList<>();
        inProgressList = loadServices(IN_PROGRESS_LIST_ID);
        if (inProgressList == null) inProgressList = new ArrayList<>();

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar = findViewById(R.id.my_toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();

        TabLayout tabs = findViewById(R.id.tabs);
        tabs.setOnTabSelectedListener(tabListener);

menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/my_toolbar"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity"
    android:layout_height="?attr/actionBarSize"
    xmlns:appcompat="http://schemas.android.com/apk/res-auto">
<!--        <item android:id="@+id/privacyPolicy"-->
<!--            android:title="Privacy Policy"-->
<!--            android:icon="@drawable/ic_more_vert_black_24dp"-->
<!--            app:showAsAction="always"></item>-->

</menu>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:backgroundTint="@color/appBackground"
    android:background="@color/appBackground"


    >
<include
    layout="@menu/menu"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"/>

Upvotes: 1

Views: 228

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006944

Remove:

<include
    layout="@menu/menu"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"/>

<include> is only for including layout resources, not menu resources.

Upvotes: 0

Related Questions