Error inflating class android.support.design.widget.CollapsingToolbarLayout in android
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.CollapsingToolbarLayout"
Since you are using androidx and the Material Components Library, you have to use the component in the same library.
Use:
<com.google.android.material.appbar.CollapsingToolbarLayout
..>
Instead of android.support.design.widget.CollapsingToolbarLayout
.
Error Inflating CollapsingToolbarLayout
I answered a similar post here Error inflating class CollapsingToolbarLayout
I know there is an accepted answer already, BUT it is not working (or no longer working).
I spend a couple of hours researching on this error, what I came up is this.
First, due to initial release of Android Nougat also known as Android 7.0 (API 24) compileSdkVersion 24 is now available. To do that you have to update your sdk. Step 1
Second, is to update your gradle files (internet connection required). Step 2
Also Update this part of app.gradle
Third (optional) Clean Project, Build Project (Both under Build Tab)
I hope this help someone out there and save some few hours of researching.
Cheers / Happy coding
Hope it helps.
Error inflating class CollapsingToolbarLayout
I found a solution May it work try it:
add below code in gradle build file
compile ('com.android.support:support-v4:23.4.0'){
force = true;
}
Seems like it is having version conflict issue. All support library must be of same version. However, I didn't use v4 support library before and it works.
I don't know why updatimg android studio to 2.1.1 causes the issue.
I just force all v4 library to the same as other support libraries.
Unable to inflate CollapsingToolbarLayout in Android
This code:
<android.support.design.widget.AppBarLayout
android:id="@+id/main_appbar_layout"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:layout_height="wrap_content">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
app:tabBackground="@color/colorPrimary"
app:tabIndicatorHeight="40dp"
app:tabTextColor="@color/colorAccent"
android:id="@+id/main_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/main_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
</LinearLayout>
Woks just fine in my Moto X.
All I did was removing this line: app:theme="@style/ActionBarTheme"
and tools:context=".MainActivity"
My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "br.com.hinovamobile.deletethis"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
}
Please try this code and tell me if it works for you. Or try yours in another phone.
Error inflating when adding imageview to collapsingtoolbarlayout Android
Well as the error says :
Caused by: android.content.res.Resources$NotFoundException: Resource "com.example.android.imgedit:mipmap/appbarimage" (7f0c0000) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0c0000 a=-1 r=0x7f0c0000}
Its sure that ImageView is not inflating correctly.
Make sure you copy your appbarimage inside drawable folder and change
android:src="@mipmap/appbarimage"
to
android:src="@drawable/appbarimage"
Error inflating class com.google.android.material.appbar.AppBarLayout
You're using AndroidX
tags-components which you already have AppCompat
dependencies. This will cause other issues too. Go with the Refactor -> Migrate to AndoridX
and add the mentioned dependency for the material components too.
In your build.gradle
dependencies:
implementation 'com.google.android.material:material:1.0.0'
It's coming from Material components -> com.google.android.material
as you can see so, that's why you get the error.
Remember to update the gradle
in the other build.gradle
too:
classpath 'com.android.tools.build:gradle:3.2.0'
Related Topics
How to Integrate Matlab Code Library with Android
Start Google Hangout from Intent in New Hangouts Android App
Android Emulator - Trouble Creating User Accounts
Okhttp Library - Networkonmainthreadexception on Simple Post
Android:Dither="True" Does Not Dither, What's Wrong
Firebase Dynamic Link Not Opening the App
Firebase: How to Set Default Notification Channel in Android App
Highlighting the Selected Item in the Listview in Android
Load Images from Disk Cache with Picasso If Offline
Android: Google Maps Location with Low Battery Usage
Deep Linking Not Working in Chrome
My Android Camera Uri Is Returning a Null Value, But the Samsung Fix Is in Place, Help
Get Android Subscription Status, Failed with 403
Communicating with Serial Usb Device Over Android
Android: Broadcastreceiver Intent to Detect Camera Photo Taken
Debugging Android Ndk Native Apps
Android: Custom Separator (Or Even Item) in Listview Depening on Content of Item