Android, can't add more elements with IDs, InflateException - android

I have a fragment xml containing a View at the bottom:
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
The app starts just fine.
I now add an ID to this view:
<View
android:id="#+id/myTestId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
Without making any further modifications to the code, the app crashes with the following stacktrace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package, PID: 17505
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package/com.package.MainActivity}: android.view.InflateException: Binary XML file line #56 in com.package:layout/main_panel: Binary XML file line #56 in com.package:layout/main_panel: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3635)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: android.view.InflateException: Binary XML file line #56 in com.package:layout/main_panel: Binary XML file line #56 in com.package:layout/main_panel: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #56 in com.package:layout/main_panel: 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:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:858)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1010)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at android.view.LayoutInflater.inflate(LayoutInflater.java:485)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.package.MainActivity.onCreate(MainActivity.kt:167)
at android.app.Activity.performCreate(Activity.java:8051)
at android.app.Activity.performCreate(Activity.java:8031)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)E/AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageView cannot be cast to android.view.ViewGroup
at com.google.android.material.navigation.NavigationBarItemView.<init>(NavigationBarItemView.java:97)
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)
... 31 more
The line number specified in this stacktrace is simply the beginning of this BottomNavigationView:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/btm_nav"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
app:itemHorizontalTranslationEnabled="false"
app:itemTextColor="?attr/colorOnBackGround"
app:itemIconTint="?attr/colorOnBackGround"
android:background="?attr/colorBackgroundElevated"
app:menu="#menu/menu_nav_bottom"/>
This file is in no way related to the fragment xml mentioned at the top, where i added an ID. In fact, no matter in which XML file I add elements, as soon as I add an ID to the element (no matter what id, i tried multiple) my app crashes with this weird bug. Its as if i have reached some kind of limit to using IDs. Ive worked on this app for 2 years and never ran into a similar bug.

I followed cactustictacs advice in the comment and did a Clean Build this made the app run again, however for every additional element i add, i now need to run Clean build, otherwise it will crash with the stack trace above.

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.

Error inflating Text Input Layout even though MaterialComponent style is used

I am trying to use TextInputLayout from Materials Components. Even tho my style is like this:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar", I am getting an error.
I have looked through all the similar questions on web(including stack overflow). All of them suggest to change the theme from appCompat to materialComponents, but i have already done that.
This the part of the XML that causes the error
(line 34) <com.google.android.material.textfield.TextInputLayout
android:id="#+id/til_title"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
error itself:
Caused by: android.view.InflateException: Binary XML file line #34 in com.example.happyplaces:layout/activity_add_happy_place: Binary XML file line #34 in com.example.happyplaces:layout/activity_add_happy_place: Error inflating class com.google.android.material.textfield.TextInputLayout
i have materialcomponents dependency in the build file:
implementation 'com.google.android.material:material:1.7.0-alpha03'
here is the full stack trace:
2022-08-15 10:08:31.489 16671-16671/com.example.happyplaces E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.happyplaces, PID: 16671
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.happyplaces/com.example.happyplaces.AddHappyPlaceActivity}: android.view.InflateException: Binary XML file line #34 in com.example.happyplaces:layout/activity_add_happy_place: Binary XML file line #34 in com.example.happyplaces:layout/activity_add_happy_place: Error inflating class com.google.android.material.textfield.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3271)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: android.view.InflateException: Binary XML file line #34 in com.example.happyplaces:layout/activity_add_happy_place: Binary XML file line #34 in com.example.happyplaces:layout/activity_add_happy_place: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #34 in com.example.happyplaces:layout/activity_add_happy_place: Error inflating class com.google.android.material.textfield.TextInputLayout
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:854)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at com.example.happyplaces.databinding.ActivityAddHappyPlaceBinding.inflate(ActivityAddHappyPlaceBinding.java:104)
at com.example.happyplaces.databinding.ActivityAddHappyPlaceBinding.inflate(ActivityAddHappyPlaceBinding.java:98)
at com.example.happyplaces.AddHappyPlaceActivity.onCreate(AddHappyPlaceActivity.kt:12)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3246)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
2022-08-15 10:08:31.491 16671-16671/com.example.happyplaces E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:241)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:215)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:143)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:113)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:467)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:446)
... 31 more
i cant find out what causes the error here. Any help would be very appreciated.
The problem is I was still using AppCompat library for another style. That was the cause. It took me one day to figure out.

Error inflating class androidx.fragment.app.FragmentContainerView

I updated navigation component to 2.3.2 version.
In the 2.3.1 version work normally
I was going through the documentation and I did not find anything about the error or about any update in the component
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.m.marketplace, PID: 16698
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.m.marketplace/com.m.marketplace.ui.MainActivity}: android.view.InflateException: Binary XML file line #11 in com.m.marketplace:layout/activity_main: Binary XML file line #11 in com.m.marketplace:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3460)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2047)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7590)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: android.view.InflateException: Binary XML file line #11 in com.m.marketplace:layout/activity_main: Binary XML file line #11 in com.m.marketplace:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #11 in com.m.marketplace:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: java.lang.IllegalArgumentException
at androidx.lifecycle.LifecycleRegistry.downEvent(LifecycleRegistry.java:263)
at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:314)
at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:334)
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
at androidx.lifecycle.LifecycleRegistry.setCurrentState(LifecycleRegistry.java:118)
at androidx.navigation.NavBackStackEntry.updateState(NavBackStackEntry.java:150)
at androidx.navigation.NavBackStackEntry.setMaxLifecycle(NavBackStackEntry.java:130)
at androidx.navigation.NavController.popBackStackInternal(NavController.java:325)
at androidx.navigation.NavController.navigate(NavController.java:1050)
at androidx.navigation.NavController.navigate(NavController.java:942)
at com.m.marketplace.utils.ktx.NavControllerKt.navigateSafe(NavController.kt:17)
at com.m.marketplace.utils.ktx.NavControllerKt.navigateSafe$default(NavController.kt:13)
at com.m.marketplace.utils.ktx.FragmentKt.navigate(Fragment.kt:15)
at com.m.marketplace.ui.login.view.PreviousLoginDialog.goToHome(PreviousLoginDialog.kt:119)
at com.m.marketplace.ui.login.view.PreviousLoginDialog.access$goToHome(PreviousLoginDialog.kt:28)
at com.m.marketplace.ui.login.view.PreviousLoginDialog$firstInit$1.invoke(PreviousLoginDialog.kt:111)
at com.m.marketplace.ui.login.view.PreviousLoginDialog$firstInit$1.invoke(PreviousLoginDialog.kt:28)
at com.m.marketplace.ui.login.view.PreviousLoginDialog.onCreate(PreviousLoginDialog.kt:44)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1175)
at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2224)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1997)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
E/AndroidRuntime: at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2629)
at androidx.fragment.app.FragmentManager.dispatchCreate(FragmentManager.java:2571)
at androidx.fragment.app.Fragment.onCreate(Fragment.java:1685)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:264)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1175)
at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2224)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1997)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953)
at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1818)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:303)
at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.java:166)
at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:51)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:335)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1073)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1001)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.m.marketplace.ui.MainActivity.onCreate(MainActivity.kt:50)
at android.app.Activity.performCreate(Activity.java:7893)
at android.app.Activity.performCreate(Activity.java:7880)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3286)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3460)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2047)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7590)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
I was facing the same problem and I figured out that Android studio is not adding name tags in navigation graph. So, adding name tag in navigation graph xml worked for me.
In nav_graph.xml
<fragment
android:id="#+id/loginFragment"
android:name="com.example.MyApp.fragments.LoginFragment"
android:label="fragment_login"
tools:layout="#layout/fragment_login">
Or if you are not sure then switch to the design and in attributes tab on right side select the class name from drop-down list
If you're using Jetpack Compose change MainActivity extends to AppCompatActivity instead of CompatActivity
First make sure you have added ID to your nav graph and fragment container view. Also check fragment (declared asstart destination) does not have any instantiation issue.
When using Koin, adding android:name=".MyApplication" in application in the manifest, fixed this error and the "Accessing hidden method" warnings that were appearing before the error

Android app crashes when I add a layout element with an id (BottomNavigationView)

EDIT: SOLVED (in the worst way possible)
Turns out my hard drive is corrupted. I'm sorry for wasting your time.
I'm currently running into a error. When coding yesterday, everything worked and went smoothly. Now, all of a sudden, my app crashes for some reason.
Whenever I add a layout element with an id, say:
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/newButton"/>
the app crashes on run.
However, if I remove the ID, so that the layout code would be something like:
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"/>
the app runs normally.
This is the logCat error I get:
2020-08-04 14:33:14.994 17775-17775/com.example.cloooset E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.cloooset, PID: 17775
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cloooset/com.simonbergmark.cloooset.MainActivity}: android.view.InflateException: Binary XML file line #8 in com.example.cloooset:layout/activity_main: Binary XML file line #8 in com.example.cloooset:layout/activity_main: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3632)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3784)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2270)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8125)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: android.view.InflateException: Binary XML file line #8 in com.example.cloooset:layout/activity_main: Binary XML file line #8 in com.example.cloooset:layout/activity_main: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #8 in com.example.cloooset:layout/activity_main: 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:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:854)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.simonbergmark.cloooset.MainActivity.onCreate(MainActivity.kt:44)
at android.app.Activity.performCreate(Activity.java:7957)
at android.app.Activity.performCreate(Activity.java:7946)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3607)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3784)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2270)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8125)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2020-08-04 14:33:14.995 17775-17775/com.example.cloooset E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setImportantForAccessibility(int)' on a null object reference
at androidx.core.view.ViewCompat.setImportantForAccessibility(ViewCompat.java:1119)
at com.google.android.material.bottomnavigation.BottomNavigationItemView.<init>(BottomNavigationItemView.java:101)
at com.google.android.material.bottomnavigation.BottomNavigationItemView.<init>(BottomNavigationItemView.java:84)
at com.google.android.material.bottomnavigation.BottomNavigationItemView.<init>(BottomNavigationItemView.java:80)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView.getNewItem(BottomNavigationMenuView.java:589)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView.buildMenuView(BottomNavigationMenuView.java:521)
at com.google.android.material.bottomnavigation.BottomNavigationPresenter.updateMenuView(BottomNavigationPresenter.java:67)
at com.google.android.material.bottomnavigation.BottomNavigationView.inflateMenu(BottomNavigationView.java:344)
at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:226)
at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:133)
... 28 more
This is the BottomNavigationView code:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
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" />
And this is MainActivity:44
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val navView: BottomNavigationView = findViewById(R.id.nav_view)
Kindly help

Material Component Library version 1.1.0 not working

I want to use the startIconDrawable feature that is present in the material component library version 1.1.0. But when I upgrade from version 1.0.0 to version 1.1.0, the outlined box disappears and the activity crashes. Please Help
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/username"
android:layout_marginTop="20dp"
android:hint="Username"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
Log after clicking the button
2020-06-04 21:09:55.873 5024-5024/com.example.digidocsbeta E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.digidocsbeta, PID: 5024
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.digidocsbeta/com.example.digidocsbeta.Login}: android.view.InflateException: Binary XML file line #53 in com.example.digidocsbeta:layout/activity_login: Binary XML file line #53 in com.example.digidocsbeta:layout/activity_login: Error inflating class com.google.android.material.textfield.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3448)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
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:1068)
Caused by: android.view.InflateException: Binary XML file line #53 in com.example.digidocsbeta:layout/activity_login: Binary XML file line #53 in com.example.digidocsbeta:layout/activity_login: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #53 in com.example.digidocsbeta:layout/activity_login: Error inflating class com.google.android.material.textfield.TextInputLayout
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:854)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.example.digidocsbeta.Login.onCreate(Login.java:12)
at android.app.Activity.performCreate(Activity.java:7955)
at android.app.Activity.performCreate(Activity.java:7944)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3423)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
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:1068)
2020-06-04 21:09:55.874 5024-5024/com.example.digidocsbeta E/AndroidRuntime: Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:248)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:222)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:150)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:120)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:424)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:396)
... 30 more
2020-06-04 21:09:55.895 5024-5024/com.example.digidocsbeta I/Process: Sending signal. PID: 5024 SIG: 9

Categories

Resources