1

I've checked extensively on StackOverflow & it's a frequent question but I failed to use any of the solutions to resolve my issue. I migrated my app to AndoridX and then my app started to crash after migration on NavigationView. However, if I comment out the code of NavigationView, the app is working fine. Please view all my xml codes and the error log too. I already checked this related question on the same topic but my crash is not resolved from the answers:

Layout codes:

layout_base.xml

    <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <View
                android:id="@+id/anchor_view"
                android:layout_width="20sp"
                android:layout_height="5sp"
                android:layout_alignParentRight="true"></View>
        </RelativeLayout>

        <androidx.drawerlayout.widget.DrawerLayout
            android:id="@+id/drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:id="@+id/child"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <include layout="@layout/layout_tool_bar">

                </include>

                <RelativeLayout
                    android:id="@+id/rlt_child_content"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                </RelativeLayout>
            </LinearLayout>

            <com.google.android.material.navigation.NavigationView
                android:id="@+id/navigation"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="start">


                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <ListView
                        android:id="@+id/lst_menu_items"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_above="@+id/ll_menu_options"
                        android:dividerHeight="0.0sp"
                        android:scrollbars="none" />

                    <LinearLayout
                        android:id="@+id/ll_menu_options"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_above="@+id/iv_powered_by"
                        android:layout_marginLeft="15dp"
                        android:layout_marginRight="20dp"
                        android:layout_marginBottom="15dp"
                        android:orientation="horizontal"
                        android:paddingTop="5dp"
                        android:visibility="gone">

                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="0.5"
                            android:gravity="center_horizontal"
                            android:orientation="vertical"
                            android:visibility="invisible">

                            <ImageView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                 />

                        </LinearLayout>

                        <LinearLayout
                            android:id="@+id/ll_facebook"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:gravity="center_horizontal"
                            android:orientation="vertical">

                            <ImageView
                                android:id="@+id/iv_facebook"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                />
                        </LinearLayout>

                        <LinearLayout
                            android:id="@+id/ll_twitter"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:gravity="center_horizontal"
                            android:orientation="vertical"
                            android:visibility="visible">

                            <ImageView
                                android:id="@+id/iv_twitter"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                             />
                        </LinearLayout>

                        <LinearLayout
                            android:id="@+id/ll_instagram_page"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:gravity="center_horizontal"
                            android:orientation="vertical"
                            android:visibility="visible">

                            <ImageView
                                android:id="@+id/iv_in"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                 />


                        </LinearLayout>

                        <LinearLayout
                            android:id="@+id/ll_gplus"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="0.5"
                            android:gravity="center_horizontal"
                            android:orientation="vertical"
                            android:visibility="invisible">

                            <ImageView
                                android:id="@+id/iv_gplus"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                 />

                        </LinearLayout>
                    </LinearLayout>

                    <ImageView
                        android:id="@+id/iv_powered_by"
                        android:layout_width="match_parent"
                        android:layout_height="9dp"
                        android:layout_alignParentBottom="true"
                        android:layout_marginBottom="18dp"
                        android:visibility="gone" />

                </RelativeLayout>
            </com.google.android.material.navigation.NavigationView>

        </androidx.drawerlayout.widget.DrawerLayout>


        <include layout="@layout/layout_fab"></include>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</RelativeLayout>

The app crashes on this line: setContentView(R.layout.layout_base_activity);

Also I am using Theme.AppCompat.Light.NoActionBar theme (check the comment below)

Error log:

android.view.InflateException: Binary XML file line #48: Binary XML file line #48: Error inflating class com.google.android.material.navigation.NavigationView
            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 #48: Binary XML file line #48: Error inflating class com.google.android.material.navigation.NavigationView
         Caused by: android.view.InflateException: Binary XML file line #48: 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 uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(CalligraphyLayoutInflater.java:211)
            at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(CalligraphyLayoutInflater.java:20)
            at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:302)
            at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
            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.rInflate(LayoutInflater.java:866)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
            at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
            at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
            at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
            at com.pentaloop.playerxtreme.presentation.activities.FileManagerActivity.onCreate(FileManagerActivity.java:155)
            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)

build.gradle

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'
implementation 'com.google.android.gms:play-services-analytics:15.0.2'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'org.apache.commons:commons-lang3:3.7'
implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'jp.wasabeef:blurry:3.0.0'
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.github.satyan:sugar:1.5'
implementation 'info.hoang8f:android-segmented:1.0.6'
implementation 'jcifs:jcifs:1.3.17'
implementation 'com.android.support:multidex:1.0.1'
implementation 'com.squareup.okhttp3:okhttp:3.9.1'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.jpardogo.googleprogressbar:library:1.2.0'
implementation 'com.github.pwittchen:reactivewifi-rx2:0.3.0'
implementation 'com.github.pwittchen:reactivenetwork-rx2:3.0.6'
implementation 'com.karumi:dexter:5.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.ext.kotlinx_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.ext.kotlinx_version"

//Android X

implementation "androidx.preference:preference:1.0.0"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha07'

}

PS: I have looked at the possible duplicate question, and the answer for that involves the android.support library. However, since I am not using the support or design libraries in my code, the solution doesn't apply to me.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Muhammad Tufail
  • 326
  • 5
  • 14

2 Answers2

0

Inside DrawerLayout, you've used android:drawingCacheQuality="low". When set to low quality, the drawing cache used a lower color depth, thus losing precision in rendering gradients, hence uses less memory. But android:drawingCacheQuality has been deprecated, see the official documentation here. Use Canvas & Pixel Api instead, programmatically. See this answer by @mostafa-monowar for an implementation.

SaadAAkash
  • 3,065
  • 3
  • 19
  • 25
  • if i remove this line android:drawingCacheQuality="low" then the app also crash. – Muhammad Tufail Oct 09 '19 at 07:22
  • I didn't tell you to remove, read carefully, implement Pixel Api to achieve the same. Also, to fix the current issue, check the other 2 XML layouts or post the codes in the question that you've included in this Layout code, which are `layout_tool_bar` & `layout_fab`. – SaadAAkash Oct 09 '19 at 07:24
  • i mention in the question when i remove com.google.android.material.navigation.NavigationView app working fine – Muhammad Tufail Oct 09 '19 at 07:30
  • the issue is in NavigationView because when i remove this app run – Muhammad Tufail Oct 09 '19 at 07:33
  • 1
    @SaadAAkashi have create a Drawer in the seperate project using androidx its working fine but when i add the same code in my project the the app Crash with same error – Muhammad Tufail Oct 11 '19 at 06:51
0

You are using a Theme.AppCompat.Light.NoActionBar theme.
As described in the getting started doc, in your app you have to use a Material Components Theme.

Something like:

<style name="Theme.MyApp" parent="Theme.MaterialComponents.*">
    <!-- ... -->
</style>

using one of these:

Theme.MaterialComponents
Theme.MaterialComponents.NoActionBar
Theme.MaterialComponents.Light
Theme.MaterialComponents.Light.NoActionBar
Theme.MaterialComponents.Light.DarkActionBar
Theme.MaterialComponents.DayNight
Theme.MaterialComponents.DayNight.NoActionBar
Theme.MaterialComponents.DayNight.DarkActionBar

If you cannot change your theme to inherit from a Material Components theme, you can inherit from a Material Components Bridge theme.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Thanks for the response. i changed the theme of my application but app crash again i think the crash is in NavigationView when i remove navigation view i don't know why application run fine without any crash or error – Muhammad Tufail Oct 09 '19 at 07:59
  • i have create a Drawer in the seperate project using androidx its working fine but when i add the same code in my project the the app Crash with same error – Muhammad Tufail Oct 11 '19 at 06:51