Home > OS >  App does not open on Android 6.0.1. But works on emulator and Android 10
App does not open on Android 6.0.1. But works on emulator and Android 10

Time:06-26

I created an app with five fragments and bottomnavigationview on android java , and this works fine android 10 and emulator. When I tried running on android 6.0.1 , the app crashes.

I tried available solutions on internet but all in vein. I had been stuck here for large amount of time and any help towards the solution is appreciated.

Any other lines of code required for clarification can be provided, if asked.

This is the logcat

2022-06-24 11:12:45.252 29202-29202/com.package.packagename E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package.packagename, PID: 29202
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.packagename/com.package.packagename.activities.HomeActivity}: android.view.InflateException: Binary XML file line #27: Binary XML file line #27: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2492)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2552)
    at android.app.ActivityThread.access$1000(ActivityThread.java:166)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)
 Caused by: android.view.InflateException: Binary XML file line #27: Binary XML file line #27: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
    at android.view.LayoutInflater.inflate(LayoutInflater.java:545)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
    at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:64)
    at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:58)
    at com.package.packagename.activities.HomeActivity.onCreate(HomeActivity.java:30)
    at android.app.Activity.performCreate(Activity.java:6308)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2445)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2552) 
    at android.app.ActivityThread.access$1000(ActivityThread.java:166) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5541) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737) 
 Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
    at android.view.LayoutInflater.createView(LayoutInflater.java:654)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:809)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:749)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:880)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:521)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
    at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:64) 
    at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:58) 
    at com.package.packagename.activities.HomeActivity.onCreate(HomeActivity.java:30) 
    at android.app.Activity.performCreate(Activity.java:6308) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2445) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2552) 
    at android.app.ActivityThread.access$1000(ActivityThread.java:166) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5541) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737) 
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance(Native Method)
    at android.view.LayoutInflater.createView(LayoutInflater.java:628)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:809) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:749) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:880) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:521) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
    at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:64) 
    at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:58) 
    at com.package.packagename.activities.HomeActivity.onCreate(HomeActivity.java:30) 
    at android.app.Activity.performCreate(Activity.java:6308) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2445) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2552) 
    at android.app.ActivityThread.access$1000(ActivityThread.java:166) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5541) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737) 
 Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070069
    at android.content.res.Resources.getValue(Resources.java:1375)
    at android.content.res.VivoResources.getValue(VivoResources.java:191)
    at androidx.appcompat.widget.ResourceManagerInternal.loadDrawableFromDelegates(ResourceManagerInternal.java:256)
    at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:143)
    at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:136)
    at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:66)
    at androidx.appcompat.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:505)
    at com.google.android.material.navigation.NavigationBarItemView.initialize(NavigationBarItemView.java:196)
    at com.google.android.material.navigation.NavigationBarMenuView.buildMenuView(NavigationBarMenuView.java:707)
    at com.google.android.material.navigation.NavigationBarPresenter.updateMenuView(NavigationBarPresenter.java:72)
    at com.google.android.material.navigation.NavigationBarView.inflateMenu(NavigationBarView.java:386)
    at com.google.android.material.navigation.NavigationBarView.<init>(NavigationBarView.java:280)
    at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:108)
    at com.google.android.material.bottomna

This is the HomeActivity.java

public class HomeActivity extends AppCompatActivity {

private ActivityHomeBinding binding;
Fragment fragment;

@SuppressLint("NonConstantResourceId")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    binding = ActivityHomeBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());

    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle("BIKE TAXI ADMIN");
    setSupportActionBar(toolbar);

    BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
    bottomNavigationView.setSelectedItemId(R.id.home);
    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit();

    bottomNavigationView.setOnItemSelectedListener(item -> {
        switch (item.getItemId()) {
            case R.id.home:
                //toolbar.setTitle("Shop");
                fragment = new HomeFragment();
                loadFragment(fragment);
                return true;
            case R.id.offer:
                //                    toolbar.setTitle("My Gifts");
                fragment = new OffersFragment();
                loadFragment(fragment);
                return true;
            case R.id.reviews:
                //                    toolbar.setTitle("My Gifts");
                fragment = new ReviewsFragment();
                loadFragment(fragment);
                return true;
            case R.id.notifications:
                //                    toolbar.setTitle("Cart");
                fragment = new NotificationsFragment();
                loadFragment(fragment);
                return true;
            case R.id.earnings:
                //                    toolbar.setTitle("Profile");
                fragment = new EarningsFragment();
                loadFragment(fragment);
                return true;
        }
        return false;
    });

}

private void loadFragment(Fragment fragment) {
    // load fragment
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.fragment_container, fragment);
    transaction.addToBackStack(null);
    transaction.commit();
}

This is the activity_home.xml

<?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"
 android:id="@ id/container"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@drawable/page_gradient">

 <com.google.android.material.appbar.AppBarLayout
    android:id="@ id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/MyAppTheme.AppBarOverlay">

    <include
        android:id="@ id/toolbar"
        layout="@layout/toolbar_material" />
 </com.google.android.material.appbar.AppBarLayout>

 <FrameLayout
    android:layout_below="@id/appBarLayout"
    android:id="@ id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/bottomNavigationView" />

 <com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@ id/bottomNavigationView"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/nav_background"
    app:itemIconTint="@color/nav_color"
    app:itemTextColor="@color/nav_color"
    app:menu="@menu/bottom_nav_menu" />

</RelativeLayout>

CodePudding user response:

your problem lies in here Resources$NotFoundException - you are probably using some icons for BottomNavigationView and you don't have all density variants. e.g. you have some icon in drawable-hdpi and app works on devices/emulators with HDPI screen, but crashes on XXDPI as there is no image in drawable-xxhdpi. no matter OS version

there is also a chance for similar problem related to other resources, e.g. text - you have translated some text in values-en/strings.xml, but there is no equivalent line in default values/strings.xml - app works on en-lang devices, crashes on other

due to general Resources$NotFoundException I suggest to inspect all your resources, at first drawables

  • Related