java.lang.Classnotfoundexception: android.support.v7.widget.Toolbar

Asked

Viewed 159 times

1

OFFICIAL ANDROID DOCUMENTATION ABOUT TOOLBAR

I’m following the official documentation of Android, and even so I’m having problems as it generated this error.

Caused by: android.view.Inflateexception: Binary XML file line #9 in com.resource.actionbar:layout/activity_main: Binary XML file line #5 in com.resource.actionbar:layout/Toolbar: Error inflating class android.support.v7.widget.Toolbar Caused by: android.view.Inflateexception: Binary XML file line #5 in com.resource.actionbar:layout/Toolbar: Error inflating class android.support.v7.widget.Toolbar Caused by: java.lang.Classnotfoundexception: android.support.v7.widget.Toolbar at java.lang.Class.classForName(Native Method)

I follow all recommendations This is my Activity.

package com.resource.actionbar;

import androidx.appcompat.app.AppCompatActivity;


import android.os.Bundle;
import android.widget.Toolbar;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
        setActionBar(myToolbar);
    }
}

I tried to change this one android.widget.Toolbar for this androidx.appcompat.widget.Toolbar and it still didn’t work! I need help!

  • 1

    You could also post the XML layout of this App, by your Stacktracer I believe the problem is there, but I need to confirm to be sure.

1 answer

0


The problem was in my XML file, I took this model from Github, and it worked!

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


       <Toolbar
           android:id="@+id/toolbar"
           android:layout_width="match_parent"
           android:layout_height="?android:attr/actionBarSize"
           android:background="?android:attr/colorPrimary"
           android:elevation="4dp"
           android:theme="@android:style/ThemeOverlay.Material.ActionBar"
           android:popupTheme="@android:style/ThemeOverlay.Material.Light"
           tools:ignore="MissingConstraints" />


    </androidx.constraintlayout.widget.ConstraintLayout>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.