The exception message:
android.support.design.widget.CoordinatorLayout cannot be cast to android.support.v7.widget.Toolbar
The exception message:
android.support.design.widget.CoordinatorLayout cannot be cast to android.support.v7.widget.Toolbar
welcome to SO.
The error means exactly what it says: You're trying to use an object of type CoordinatorLayout
as if it was a Toolbar
-object. You need to find out where that is happening in your code, and correct it by passing the correct object.
From your screenshot, I would guess you should be able to find it by looking at the places where you're using the variable toolbar
.
(Sounds like you're trying to create a tool-bar, but accidentally passing a layout-object to the toolbar
-variable instead of an actual toolbar-object).
PS: If you want more help, it would be useful to include part of your code (especially the lines the exception is thrown on), and also your stack trace. You can update your question using the edit
link below your original post.
ClassCastException is generated when you try to cast instance to a class of which is not an instance. Here in your case you are trying to cast your CoordinatorLayout
to Toolbar
. Check if you have assigned correct id in findviewbyId()
for toolbar object.
app_bar_main.xml
code? Please avoid posting the screenshot as it would be difficult for code analysis.