Android ClassNotFoundException with appcompat-v7:28.0.0 - java

I'm developing an Android application and I try to use the toolbar to add some functionality on it; that's why I'm using appcompat-v7 module.
I have followed this tutorial (Sorry because it's in spanish) and I have updated my IDE with the Compatibility Support package, I also added the new module to my Gradle file and I have updated the design XML of my app with this new toolbar (I can see this toolbar in the design editor).
But, when I launch my application, I get following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.Toolbar" on path: DexPathList[[zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/base.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_resources_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(...
My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.gomar.gomar_sanidad"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
}
A sample of my activity_main.xml with the toolbar(Design XML):
<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=".NuevaFicha">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar"
app:layout_constraintVertical_bias="0.0">
....
I have tried what is said here (Checked ids, Cleaned project, Invalidated caches...) but none of these solutions had the desired results. Do you have any idea?
Thanks in advance.

you are using both androidx and AppCompat hence the error.consider using either.
implementation 'com.android.support:appcompat-v7:28.0.0' //this is appcompat
implementation 'androidx.appcompat:appcompat:1.0.0-beta01' //this is android x
you can not use androidx and android support at the same time.
see how to migrate to androidX

Your project is initialized as androidx project! if you dont want to use androidX components first remove this line from your gradle.properties file :
android.useAndroidX=true
Then replace all androidx dependencies with appcompat versions.
if you started a simple empty project you dont need to refactor this project simply create a new appcompat project instead of androidx project.

If your gradle.properties file has the property set as below
android.useAndroidX=true
Replace
android.support.v7.widget.Toolbar
With
androidx.appcompat.widget.Toolbar

Related

android.view.InflateException: always error

I have frustrating error that I cannot explain. Here is my main activity layout file:
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.asser.egycab"
minSdkVersion 23
targetSdkVersion 29
versionCode 5
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
//Horizontal date picker
implementation 'joda-time:joda-time:2.9.7'
//Timeline
// implementation 'com.github.vipulasri:timelineview:1.0.6'
//Calendar
implementation 'com.applandeo:material-calendar-view:1.4.0'
//Paypal
implementation 'com.paypal.sdk:paypal-android-sdk:2.16.0'
//Credit Card
implementation 'com.craftman.cardform:cardform:0.0.2'
//Job Scheduler
implementation 'com.github.simplymadeapps:QuickPeriodicJobScheduler:-SNAPSHOT'
implementation 'com.github.jd-alexander:library:1.1.0'
//Volley
implementation 'com.mcxiaoke.volley:library-aar:1.0.1'
//Google Map
implementation 'com.google.android.gms:play-services-location:18.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation('com.google.android.libraries.places:places:2.4.0') {
exclude module: 'volley'
}
//Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
//Place Picker
implementation 'com.sucho:placepicker:0.1.8'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.31'
//Firebase
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.firebase:firebase-core:18.0.2'
implementation 'com.google.firebase:firebase-messaging:21.0.1'
//Retrofit
implementation('com.squareup.retrofit2:retrofit:2.9.0') {
// exclude Retrofit’s OkHttp peer-dependency module and define your own module import
exclude module: 'okhttp'
}
implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2'
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
//Braintree
implementation 'com.braintreepayments.api:drop-in:5.1.0'
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
rootProject.allprojects {
repositories {
maven {
url "https://cardinalcommerce.bintray.com/android"
credentials {
username 'braintree-team-sdk#cardinalcommerce'
password '220cc9476025679c4e5c843666c27d97cfb0f951'
}
}
}
}
The error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.asser.egycab, PID: 12254
android.view.InflateException: Binary XML file line #175 in com.asser.egycab:layout/fragment_bottom_sheet_booking: Binary XML file line #175 in com.asser.egycab:layout/fragment_bottom_sheet_booking: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #175 in com.asser.egycab:layout/fragment_bottom_sheet_booking: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:855)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1012)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:963)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1142)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1103)
at com.asser.egycab.fragment.customer.BottomSheetFragmentBooking.onCreateView(BottomSheetFragmentBooking.java:127) 
I Don't know the reall error here
android.view.InflateException: Binary XML file line #175
android.view.InflateException: Binary XML file line #175 in com.asser.egycab:layout/fragment_bottom_sheet_booking: Binary XML file line #175 in com.asser
Line #175:
<com.google.android.material.textfield.TextInputLayout
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:id="#+id/intput_layout_place"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel">
<EditText
android:drawableTint="#color/colorLogoBlack"
android:drawableEnd="#drawable/ic_location_pin_"
android:hint="#string/specify_exactly_your_location"
android:textSize="16sp"
android:id="#+id/input_place"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:id="#+id/intput_layout_people_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel">
<EditText
android:drawableTint="#color/colorLogoBlack"
android:drawableEnd="#drawable/ic_team"
android:maxLength="2"
android:hint="#string/number_of_people"
android:textSize="16sp"
android:id="#+id/people_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout>
And Line #127:
View rootView = inflater.inflate(R.layout.fragment_bottom_sheet_booking, container, false);
So how this error could be fixed, I search here and on Google a lot but no luck!.
Finaly i solve it
By changing <style name="TextLabel" parent="TextAppearance.AppCompat">
To <style name="TextLabel" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">

Not able to use CoordinatorLayout in Android Studio

My problem is that I am not able to use CoordinatorLayout in Android Studio despite adding all the possible dependencies in my build.gradle file. The class is not instantinated.
Here's my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.uiuxpractical4materialdesign"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
}
activity_main.xml:
<?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">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
The Error:
java.lang.NoClassDefFoundError: androidx/coordinatorlayout/R$attr
at androidx.coordinatorlayout.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:211)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:403)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:186)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:144)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:309)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:418)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:429)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:333)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:323)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:394)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:200)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:572)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$5(RenderTask.java:698)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Due to this, the class is not instantinated and I get something like this:-
Also, here a small picture of the error too:-
Thanks for everyone helping out there to solve this issue.
Please also inform if you need anything else.
try to add this line in your dependencies in build.gradle
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:design:29.0.2'
don't worry about the difference between com.android..... and androidx.... This implementation androidx. automatically migrate the implementation if your android studio is higher than 3.2.
you can check this link.https://stackoverflow.com/a/58619780/10075771 it will help you understand also the situation :)
Hoping i help you in little way :)
try adding below dependencies
implementation 'com.android.support:appcompat-v7:23.1.1'
implementation 'com.android.support:design:23.1.1'
Hope this will work for you.

App crashing android studio after moving project folder

Three weeks ago, I decided to move my project from the downloads folder on my Mac to my desktop. After moving the project, I realized that I wasn't able to even see anything from the project. So I decided to move the project back into the downloads folder when it originally was in, and I was able to check my project again but unfortunately I am not able to run the project on my phone and I am getting a strange error message that I am not able to find a solution for on the internet. I will show you the error message and some XML code of the activity as well.
XML code:
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="427dp"
android:layout_height="82dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_nav_menu" />
<fragment
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="413dp"
android:layout_height="49dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#id/nav_view"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:navGraph="#navigation/mobile_navigation" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/home_view_message"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/nav_host_fragment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.027" />
<Spinner
android:id="#+id/channel_spinner"
android:layout_width="409dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#+id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView6"
app:layout_constraintVertical_bias="0.162" />
<Button
android:id="#+id/check_button"
android:layout_width="157dp"
android:layout_height="58dp"
android:text="#string/home_button_text"
app:layout_constraintBottom_toTopOf="#+id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/channel_spinner"
app:layout_constraintVertical_bias="0.418" />
</androidx.constraintlayout.widget.ConstraintLayout>
Error message:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mychannels/com.example.mychannels.MainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3092)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3235)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6990)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
Caused by: java.lang.reflect.InvocationTargetException
Build.gradle (app level):
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.mychannels"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.preference:preference:1.1.0-alpha05'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
File -> Invalidate caches/restart & try to import it. File -> new -> import project
I think you missed to add implementation 'com.google.android.material:material:1.1.0-alpha1' In your app gradle file. Just add this gradle inside
dependencies { } black and sync your project. Now, this error should be removed and aproject will run successfully.
After some searches about my problem and after trying many times to fix it, I re tried to delete the android:background="?android:attr/windowBackground" statement from the XML code, the app opened and ran without any problems on my phone. I tried to do so the first time when I opened this discussion but it didn't work. Thank you for helping me to solve my problem!
I ran into this problem recently and the only thing that truly helped me open a project after having moved it to another folder was to completely delete the build folder (that one located inside app folder) before launching Android Studio. Tested on Android Studio 4.1.3 / Windows 10.

How to solve Error inflating class android.support.design.widget.BottomNavigationView?

I'm trying to implement the method Bottom Navigation view but when i run my code i get this error
Caused by: android.view.InflateException: Binary XML file line #19: Binary XML file line #19: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.BottomNavigationView" on path: DexPathList[
what should i do to solve this problems?
activity_home layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#color/white"
app:layout_behavior="android:.support.design.widget.BottomSheetBehaviour"
tools:context=".HomeActivity">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_navigation">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/purpleBae"
app:itemIconTint="#android:color/white"
app:itemTextColor="#android:color/white"
app:menu="#menu/home_menu" />
</RelativeLayout>
build.gradle(Module app)
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.gerobokgoapp"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
// Exclude file to avoid
// Error: Duplicate files during packaging of APK
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
compileOptions {
incremental true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//add libraries
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.firebase:firebase-firestore:21.0.0'
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
implementation 'com.facebook.android:account-kit-sdk:4.39.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
testImplementation 'androidx.test.ext:junit:1.1.1'
}
You cannot mix both support and androidx libraries together in the same project, there will surely be conflicts unless you're using Jetpack tool. Migrate your support libraries to androidx
Also References in an Androidx layout file should all be androidx artifacts and not otherwise.
Hence tag like this:
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/purpleBae"
app:itemIconTint="#android:color/white"
app:itemTextColor="#android:color/white"
app:menu="#menu/home_menu" />
Should be:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/purpleBae"
app:itemIconTint="#android:color/white"
app:itemTextColor="#android:color/white"
app:menu="#menu/home_menu" />
add below dependency:
dependencies {
// https://mvnrepository.com/artifact/com.google.android.material/material
implementation "com.google.android.material:material:1.0.0"
}
and use com.google.android.material.bottomnavigation.BottomNavigationView instead

App restarts, Doesn't run due to AndroidRuntime Exception

Gradle build is successful logcat shows E/AndroidRuntime: FATAL EXCEPTION: main
--------Logcat Error-----------
07-27 23:04:54.813 21702-21702/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.inoalexander.justjava, PID: 21702
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.inoalexander.justjava/com.example.inoalexander.justjava.mainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.inoalexander.justjava.mainActivity" on path: DexPathList[[zip file "/data/app/com.example.inoalexander.justjava-2/base.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.inoalexander.justjava-2/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2819)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1534)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1424)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.inoalexander.justjava.mainActivity" on path: DexPathList[[zip file "/data/app/com.example.inoalexander.justjava-2/base.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.inoalexander.justjava-2/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2809)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1534) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1424) 
---------Java Code starts here----------
package com.example.inoalexander.justjava;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
display(1);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
---------XML code starts here-------------
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="16sp"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:text="Quantity" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="16sp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:text="0" />
<Button
android:id="#+id/button_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="16dp"
android:text="Order"
android:onClick="submitOrder"/>
</LinearLayout>
I'm not to sure as this is one of the first apps I've built that isn't a card. I'm not sure why it isn't running on my phone. I'm using a Galaxy Note 5 to run my build.
The Gradle build is successful and gives me no errors but when I try to run it on my device it keeps trying to restart the app until it eventually crashes the app. I have looked at a few answers here and was instructed to look at my Logcat in android studio.
I honestly don't know were to even begin within Logcat or what it even tells me, there are a lot of variations of this error I have seen but not one specific to each of the errors in my Logcat.
set multidex true to app level build.gradle file like below
android {
compileSdkVersion 27
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.core.######"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true // here change
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
also add dependency
implementation 'com.android.support:multidex:1.0.3'
finally don't forget to clean and rebuild project.
The exception says it's trying to find class mainActivity but in your code you have MainActivity.
Make sure the activity class name in AndroidManifest.xml matches your code.

Categories