BottomNavigationView inflating error. Resources$NotFoundException: Resource ID #0x0 - android

I'm having some problem with BottomNavigationView from design support library.
I am using it in my activity_main.xml:
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
app:itemIconSize="16dp"
app:labelVisibilityMode="labeled"
app:itemTextColor="#color/white"
app:itemIconTint="#color/white"
app:itemBackground="#color/medium_purple"
app:menu="#menu/main"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
The app crashes when inflating that xml. The full stack trace of the exception is below:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.frolo.musp.dev/com.alexfrolov.mp.main.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:822)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:651)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:867)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.alexfrolov.mp.main.MainActivity.onCreate(MainActivity.java:165)
at android.app.Activity.performCreate(Activity.java:7074)
at android.app.Activity.performCreate(Activity.java:7065)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:822)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:220)
at android.content.res.MiuiResourcesImpl.getValue(MiuiResourcesImpl.java:93)
at android.content.res.Resources.getColorStateList(Resources.java:1034)
at android.content.Context.getColorStateList(Context.java:631)
at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:67)
at android.support.design.internal.BottomNavigationMenuView.createDefaultColorStateList(BottomNavigationMenuView.java:467)
at android.support.design.internal.BottomNavigationMenuView.<init>(BottomNavigationMenuView.java:101)
at android.support.design.internal.BottomNavigationMenuView.<init>(BottomNavigationMenuView.java:86)
The versions of all support libs and the version of compileSdk are same. I really don't understand what a hell is that. Can anybody explain me please?
Thanks

I had this problem and it baffled me for a day or so. Basically, the BottomNav wants a colorstatelist defined for textColorSecondary in your theme as opposed to a just plain color. So I went from:
<style name="MTheme" parent="Theme.MaterialComponents.Light.Bridge">
...
<item name="android:textColorSecondary">#295055</item>
to
<style name="MTheme" parent="Theme.MaterialComponents.Light.Bridge">
...
<item name="android:textColorSecondary">#color/secondary_textcolor</item>
where secondary_textcolor equals
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:color="#295055"/>
<item android:state_enabled="false" android:color="#color/disabled"/>
</selector>
I wasted a lot of time adding and removing dependencies trying to find this solution.

The problem is in your question title
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
It means that you are using a resource that is not existent. I cannot know which it is but this is how you will fix. Go to the file #menu/main and remove all attributes for icons. You can leave the text. Add one by one to check which one is the problem. It is most likely to be that your icons have been mistakenly placed inside the folder drawable-24 instead of drawable or a higher android API folder than the one you are testing on. Sometimes we make those mistakes.
Also note that some attributes only apply starting a certain android API. Consider checking the attributes starting with app.
app:itemTextColor="#color/white"
app:itemIconTint="#color/white"
app:itemBackground="#color/medium_purple"

Related

after run the android xml file the app has install in my phone but the app is not opening

I am totally new to android development and trying to learn it by my own, I have done some coding in xml file but when I run the application, app has install in my phone but not opening.
Here is the error log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sumita.yourhelp, PID: 6407
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sumita.yourhelp/com.sumita.yourhelp.MainActivity}: android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class androidx.appcompat.widget.AppCompatButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2994)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1766)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6977)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:528)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:910)
Caused by: android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class androidx.appcompat.widget.AppCompatButton
Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class androidx.appcompat.widget.AppCompatButton
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:650)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:797)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:737)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:831)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:710)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.sumita.yourhelp.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:7227)
at android.app.Activity.performCreate(Activity.java:7218)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1766)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6977)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:528)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:910)
Caused by: java.lang.UnsupportedOperationException: Can't convert to ComplexColor: type=0x1
at android.content.res.ResourcesImpl.loadComplexColorForCookie(ResourcesImpl.java:1217)
at android.content.res.ResourcesImpl.loadComplexColorFromName(ResourcesImpl.java:1094)
at android.content.res.ResourcesImpl.loadColorStateList(ResourcesImpl.java:1173)
at android.content.res.Resources.loadColorStateList(Resources.java:1076)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:541)
at android.view.View.<init>(View.java:5180)
at android.widget.TextView.<init>(TextView.java:867)
at android.widget.Button.<init>(Button.java:166)
at android.widget.Button.<init>(Button.java:141)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:80)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:75)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:650)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:797)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:737)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:831)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:710)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.sumita.yourhelp.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:7227)
at android.app.Activity.performCreate(Activity.java:7218)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1766)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6977)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:528)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:910)
And here is the xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:padding="11dp"
android:gravity="center_horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="258dp"
android:contentDescription="#string/About"
android:scaleType="fitXY"
android:src="#drawable/ic_contact_us" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Aboutus"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="?android:attr/colorFocusedHighlight"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="12"
android:hint="enter number"
android:inputType="number" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/material_dynamic_neutral40"
android:text="contact us"
android:textColor="#color/black"/>
</LinearLayout>
Two relevant parts of your error log.
This section points to a problem in line 39 of your layout file, inflating an AppCompatButton.
Caused by: android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class androidx.appcompat.widget.AppCompatButton
There's also this in your error log:
Caused by: java.lang.UnsupportedOperationException: Can't convert to ComplexColor: type=0x1
So, taken together, your error log suggests that there's a problem with a color that's being used in an AppCompatButton on line 39 of your layout XML.
If you look at that line in your layout file, you'll see this:
android:textColor="#color/black"/>
Taken together, I would guess that you haven't defined the color you've called black correctly. Try and replace it with #android:color/black and see if that works. If it does, then you need to fix whatever color you've defined for black in your resources files.

After Adding Zoom Meeting SDK, BottomNavigationView is Crashing the app. Why this happening?

After Adding zoom sdk BottomNavigationView is crashing.
[ZoomSDKImlementation][1] https://marketplace.zoom.us/docs/sdk/native-sdks/android/build-an-app/
Here I found the problem with menu. If I removed app:menu error will gone, But menu is needed for sure.
api 'com.google.android.material:material:1.4.0'
Issue from Xml Design Tab
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="#color/colorPrimary"
app:itemIconTint="#color/bottom_nav_item_colors"
app:itemTextColor="#color/bottom_nav_item_colors"
app:labelVisibilityMode="selected"
app:menu="#menu/calf_bottom_navigation" />
at com.google.android.material.navigation.NavigationBarItemView.<init>(NavigationBarItemView.java:107)
at com.google.android.material.bottomnavigation.BottomNavigationItemView.<init>(BottomNavigationItemView.java:34)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView.createNavigationBarItemView(BottomNavigationMenuView.java:197)
at com.google.android.material.navigation.NavigationBarMenuView.getNewItem(NavigationBarMenuView.java:492)
at com.google.android.material.navigation.NavigationBarMenuView.buildMenuView(NavigationBarMenuView.java:421)
at com.google.android.material.navigation.NavigationBarPresenter.updateMenuView(NavigationBarPresenter.java:72)
at com.google.android.material.navigation.NavigationBarView.inflateMenu(NavigationBarView.java:358)
at com.google.android.material.navigation.NavigationBarView.<init>(NavigationBarView.java:226)
at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:103)
at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:98)
at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:93)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:399)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:189)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:147)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:303)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:417)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:428)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:332)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1121)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1095)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:353)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:431)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:714)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$7(RenderTask.java:870)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$2.run(RenderExecutor.kt:187)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Stacktrace when run the app
2022-02-17 16:24:16.909 6448-6448/com.lakshya.academy E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lakshya.academy, PID: 6448
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lakshya.academy/com.nuveda.calf.ui.participant.activity.ParticipantHomeActivity}: android.view.InflateException: Binary XML file line #115: Binary XML file line #115: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #115: Binary XML file line #115: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #115: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.nuveda.calf.ui.participant.activity.ParticipantHomeActivity.onCreate(ParticipantHomeActivity.kt:82)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.ViewGroup.getPaddingBottom()' on a null object reference
at com.google.android.material.navigation.NavigationBarItemView.<init>(NavigationBarItemView.java:107)
at com.google.android.material.bottomnavigation.BottomNavigationItemView.<init>(BottomNavigationItemView.java:34)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView.createNavigationBarItemView(BottomNavigationMenuView.java:197)
at com.google.android.material.navigation.NavigationBarMenuView.getNewItem(NavigationBarMenuView.java:492)
at com.google.android.material.navigation.NavigationBarMenuView.buildMenuView(NavigationBarMenuView.java:421)
2022-02-17 16:24:16.910 6448-6448/com.lakshya.academy E/AndroidRuntime: at com.google.android.material.navigation.NavigationBarPresenter.updateMenuView(NavigationBarPresenter.java:72)
at com.google.android.material.navigation.NavigationBarView.inflateMenu(NavigationBarView.java:358)
at com.google.android.material.navigation.NavigationBarView.<init>(NavigationBarView.java:226)
at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:103)
at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:98)
at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:93)```
[1]: https://marketplace.zoom.us/docs/sdk/native-sdks/android/build-an-app
I've created a fresh new app using the Empty Activity Template. Then I went to the almost empty main_activity.xml and pasted your BottomSheet.
I added your dependency to build.gradle.
I fixed the missing things:
constrains so the COnstraintLayout doesn't scream at me.
Colors, I picked random colors that come with Android.
Menu: you didn't supply this one, but I have the impression this is where your problem could be. Mine is empty, as I don't know what's in yours.
Theme: I changed the default from the template (DayNight) to Light.
And... it runs.
So, I'd start from this empty project, adding your bits one by one until you figure out what is crashing your inflation process.
Why do I think your menu is involved?
If you look at your stacktrace, the BottomNavigationView is calling its constructor init() and part of this involves inflating the menu items:
at NavigationBarItemView.<init>(NavigationBarItemView.java:107)
at BottomNavigationItemView.<init>(BottomNavigationItemView.java:34)
at BottomNavigationMenuView.createNavigationBarItemView(BottomNavigationMenuView.java:197)
at NavigationBarMenuView.getNewItem(NavigationBarMenuView.java:492)
at NavigationBarMenuView.buildMenuView(NavigationBarMenuView.java:421)
at.NavigationBarPresenter.updateMenuView(NavigationBarPresenter.java:72)
at NavigationBarView.inflateMenu(NavigationBarView.java:358)
at NavigationBarView.<init>(NavigationBarView.java:226)
Here's my sample project running:
If you are still facing this issue, it is probably being caused due to a custom implementation of an older version of design_bottom_navigation_item.xml file either in your codebase or in the SDK. This file was updated in version 1.3.0 and again in 1.4.0 of Material Component Library. Overriding it with an incompatible version will cause the app to crash.

Can't use color statelist in navigationVIew Android kotlin

I have two project one uses color statelist selector in NavigationView to change the background color of items in Navigation Drawer on different state of interactions.
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemBackground="#color/nav_bgstate_list" <------
app:itemIconTint="#color/nav_state_list" <------
app:itemTextColor="#color/nav_state_list" <------
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
These three lines causes error but when I remove them, it works fine.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Item checked -->
<item android:color="#color/brand" android:state_checked="true" />
<!-- Item pressed -->
<item android:color="#color/black" android:state_pressed="true" />
<!-- Item default -->
<item android:color="#color/brand70" />
</selector>
I copied the same code into another project and it started throwing bunch of errors. The log is below
2021-06-09 07:49:13.564 12895-12895/ca.company.project.betaversion E/AndroidRuntime: FATAL EXCEPTION: main
Process: ca.company.project.betaversion, PID: 12895
java.lang.RuntimeException: Unable to start activity ComponentInfo{ca.company.project.betaversion/ca.company.project.betaversion.MainActivity}: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.google.android.material.navigation.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:57)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:51)
at ca.company.project.betaversion.MainActivity.onCreate(MainActivity.kt:111)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2734)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.content.res.Resources$NotFoundException: Drawable ca.company.project.betaversion:color/nav_bgstate_list with resource ID #0x7f0600d9
Caused by: android.content.res.Resources$NotFoundException: File res/color/nav_bgstate_list.xml from drawable resource ID #0x7f0600d9
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:820)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:630)
at android.content.res.Resources.getDrawableForDensity(Resources.java:877)
at android.content.res.Resources.getDrawable(Resources.java:819)
at android.content.Context.getDrawable(Context.java:605)
at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:455)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:147)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:135)
2021-06-09 07:49:13.569 12895-12895/ca.company.project.betaversion E/AndroidRuntime: at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:104)
at androidx.appcompat.widget.TintTypedArray.getDrawable(TintTypedArray.java:83)
at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:196)
at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:122)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:57)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:51)
at ca.company.project.betaversion.MainActivity.onCreate(MainActivity.kt:111)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2734)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: <item> tag requires a 'drawable' attribute or child tag defining a drawable
at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:189)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:122)
at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1254)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:807)
... 36 more
I checked minSdk version, compilied sdk version, themes, gradle version, dependencies with their versions etc. and everything is same, nothing is different. I know I should be using drawable states instead of color state but I don't understand why it is working in other project but in the another one.
Edit 1
I found out that the crash was happening because of I set the itembackground with color state selector. itemIconTint and itemTextColor works fine with color state selectors. Only itemBackground crashes whenever I try to set the state selector there so I found one solution mentioned here, basically I need to add checked android:checkable="true" but even after adding this it crashed. I don't know why.
Edit 2
So I realized color state selector is working on newer version of android > 10 but not on the older version of android.

How can I solve inflating class error at Kotlin?

I'm trying to add payment from for my application. I use that library for that. I added it to my project. I'm also try delete from gradle and re-install it but it gave same error again.
Here my xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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=".OdemeSayfasi">
<com.fevziomurtekin.payview.Payview
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/payview"/>
</LinearLayout>
In run time I got error which is:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.slidework3, PID: 23708
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.slidework3/com.example.slidework3.OdemeSayfasi}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.fevziomurtekin.payview.Payview
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.fevziomurtekin.payview.Payview
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.slidework3.OdemeSayfasi.onCreate(OdemeSayfasi.kt:22)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7224) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
This error is very long so I get only first parts of it.
How can I solve it? I try to inflate layout but I can't solve it. I'm waiting for your advices and help.
I tried to replicate it and noticed this message alongside with what you have shown:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
The reason being the library uses MDC.
I had to change the existing app theme applied into Material Design Component(MDC) based, so to make avoid the error; Example: In under style.xml:
<style name="AppTheme"parent="Theme.MaterialComponents.Light.NoActionBar">
Edit: If you don't want to affect the apptheme, you can just apply a Material Component theme to just the payview.
<com.fevziomurtekin.payview.Payview
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/payview"
android:theme="#style/Theme.MaterialComponents"/>
If you want to customise your payview, just create a custom theme whose parent based on Theme.MaterialComponents .

Toast.makeText Giving "Error inflating class Textview" Exception

Every single Toast.makeText in my app is giving me a stack trace similar to this:
/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.application, PID: 8843
android.view.InflateException: Binary XML file line #27: Binary XML file line #27: Error inflating class TextView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.widget.Toast.makeText(Toast.java:263)
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:240)
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:236)
at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.widget.Toast.makeText(Toast.java:263) 
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:240) 
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:236) 
at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=16; index=1191
at android.content.res.StringBlock.get(StringBlock.java:65)
at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:1151)
at android.content.res.TypedArray.getString(TypedArray.java:195)
at android.support.v7.widget.TintTypedArray.getString(TintTypedArray.java:142)
at android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:243)
at android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:165)
at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:80)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:70)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1016)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1073)
These are some sample Toast.makeText calls that are causing it
Toast.makeText(ReportActivity.this, "Reported for " + reportType, Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.network_unavailable, Toast.LENGTH_SHORT).show();
It all started when we upgraded our Gradle libraries and started using these versions
compileSdkVersion 27
buildToolsVersion '27.0.1'
The bug apparently occurs when using support library 26+, on API 25 and lower, and is supposedly fixed in Oreo.
See: https://issuetracker.google.com/issues/64053344
The fix in my case was to change the fontFamily defined in my default theme, by extracting sans-serif-light to a string resource, that is going from this:
<style name="AppCompatTheme" parent="android:...">
<item name="fontFamily">sans-serif-light</item>
</style>
To this:
<style name="AppCompatTheme" parent="android:...">
<item name="fontFamily">#string/default_font</item>
</style>
with in my strings.xml:
<string name="default_font" translatable="false">sans-serif-light</string>
My Toast callings was with getBaseContext(). I just change it to getApplicationContext() to solve the problem.
I solved the crashing from the Toast.makeText entries all throughout the app by doing a global search for fontFamily and deleting the entries.
It seems like the font family was being defined and the new build tools and SDK didn't like that.

Categories

Resources