java.lang.ClassNotFoundException android.support.v7.widget.Toolbar [Fix]


2021-04-18 15:18:12.620 5902-5902/com.example.myapplication E/AndroidRuntime: 

 FATAL EXCEPTION: main
    Process: com.example.myapplication, PID: 5902
    java.lang.RuntimeException: Unable to start activity 
    ComponentInfo{com.example.myapplication/ com.example.myapplication.MainActivity}: 
    android.view.InflateException: Binary XML file        
    line #9 in com.example.myapplication:layout/ activity_main: 
    Binary XML file line #9 in com.example.myapplication:layout/activity_main: 
    Error inflating class android.support.v7.widget.Toolbar
 Caused by: android.view.InflateException: Binary XML file line #9 in 
 com.example.myapplication:layout/activity_main: 
Binary XML file line #9 in com.example.myapplication:layout/activity_main: 
Error inflating class android.support.v7.widget.Toolbar
     Caused by: android.view.InflateException:
 Binary XML file line #9 in com.example.myapplication:layout/activity_main: 
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) 

If you get the above error message in Android Studio LogCat Logs and your App crashes, the reason is you are trying to use android.support.v7.widget.Toolbar class that does not exist, its better to use androidx.appcompat.widget.Toolbar instead.

Example:
<androidx.appcompat.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
Android Toolbar ClassNotFound Exception
Android Toolbar ClassNotFound Exception


Have Questions? Post them here!
Advertisements
Try Out Code2care Dev Tools:

Advertisements



Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency