2

I'm totally frustrated over the bug. I completed my project and run on my device of Android version 4.4.2 and it ran sucessfully then I sucessfully uploaded in Playstore and again installed from Playstore and still it worked fine.....

But then I received a lot of crashes report from my Friends. Then I borrowed my friend device of Android Version 6.0.1 and I ran app from Android Studio and app crashed suddenly after Splashactivity started. Splashactivity started sucessfully then Before Opening Mainactivity where I have used fragment container to load 5-6 fragment...It crashed.

Below is my error log report

Caused by: android.view.InflateException: Binary XML file line #69: Binary XML file line #69: Error inflating class android.support.v7.widget.CardView
        at android.view.LayoutInflater.inflate(LayoutInflater.java:543)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
        at com.nepalpolice.cdp.main.onCreateView(main.java:69)

Here's the layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<ScrollView 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=".main">



    <LinearLayout
        android:orientation="vertical"
        android:background="@drawable/bg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">




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

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:adjustViewBounds="true"
                android:src="@drawable/main"
                />

        </RelativeLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="15dp"
            android:background="#f7f6f3"/>

        <View
            android:id="@+id/SplitLine_hor1"
            android:layout_width="match_parent"
            android:layout_height= "2dp"
            android:background="#C0C0C0" />


        <android.support.v7.widget.GridLayout
            android:id="@+id/mainGrid"
            app:orientation="horizontal"
            app:columnCount="2"
            android:background="#FEFEFE"
            app:rowCount="3"
            app:columnOrderPreserved="false"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="1dp"
            >

            <!-- Row 1 -->

            <!-- Column 1 -->
            <android.support.v7.widget.CardView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                app:cardElevation="8dp"
                app:cardCornerRadius="8dp"
                android:backgroundTint="@drawable/megaphone"
                >

                <LinearLayout
                    android:layout_gravity="center_horizontal|center_vertical"
                    android:layout_margin="16dp"
                    android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:src="@drawable/notices"
                        android:layout_gravity="center_horizontal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id='@+id/news'/>

                    <TextView
                       android:text="News "
                        android:textAlignment="center"
                        android:textColor="#0f539c"
                        android:textSize="18sp"
                        android:textStyle="bold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                </LinearLayout>

            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                app:cardElevation="8dp"
                app:cardCornerRadius="8dp"
                >

                <LinearLayout
                    android:layout_gravity="center_horizontal|center_vertical"
                    android:layout_margin="16dp"
                    android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:id='@+id/feeds'
                        android:src="@drawable/feeds"
                        android:layout_gravity="center_horizontal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:text="Blog"
                        android:textAlignment="center"
                        android:textColor="#0f539c"
                        android:textSize="18sp"
                        android:textStyle="bold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                </LinearLayout>

            </android.support.v7.widget.CardView>


  </LinearLayout>




</ScrollView>


</RelativeLayout>

and my build gradle file is

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.nepalpolice.cdp"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 5
        versionName "5.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    dexOptions {
        jumboMode true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}





dependencies {
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation("com.github.bumptech.glide:glide:4.6.1") {
        exclude group: "com.android.support"
        implementation 'com.android.support:appcompat-v7:26.+'
        implementation 'com.android.support:support-v4:26.+'
        implementation 'com.android.support:cardview-v7:26.+'
        implementation 'com.android.support:recyclerview-v7:26.+'
        implementation 'com.google.firebase:firebase-messaging:11.8.0'
        implementation 'com.google.gms:google-services:3.1.0'
        implementation 'com.android.support:design:26.+'
        implementation 'de.hdodenhof:circleimageview:2.2.0'

        implementation 'com.theartofdev.edmodo:android-image-cropper:2.5.1'
        implementation 'com.android.support:gridlayout-v7:26.+'
        implementation 'com.github.clans:fab:1.6.2'
        testCompile 'junit:junit:4.12'
        implementation 'com.google.android.gms:play-services-maps:11.8.0'
        implementation 'com.google.firebase:firebase-firestore:11.8.0'
        implementation 'id.zelory:compressor:2.1.0'
        implementation files('libs/libGoogleAnalyticsServices.jar')


    }
    apply plugin: 'com.google.gms.google-services'
}

and image file is Error log Report

and my main fragment is

  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_main, container, false);
    news   = (ImageView) view.findViewById(R.id.news);
    notice   = (ImageView) view.findViewById(R.id.notice);

How do I solve this.....I follwed many other post also but it didn't help either. Thanks in advance

Sandip Fichadiya
  • 3,430
  • 2
  • 21
  • 47
Rishiram Ranabhat
  • 155
  • 1
  • 2
  • 11
  • can you please add the errors – Mohamd Ali Mar 27 '18 at 11:58
  • @MohamdAl-Najjar I have added error both text and image file...Please check. – Rishiram Ranabhat Mar 27 '18 at 12:00
  • 1
    Test case : try using exact versions instead plus. like 26.0.1 or whatever you have – Vidhi Dave Mar 27 '18 at 12:01
  • And then clean rebuild and run – Vidhi Dave Mar 27 '18 at 12:01
  • Ok @VishvaDave let me try it..and I'll comment if it solved this or not....just a minute. – Rishiram Ranabhat Mar 27 '18 at 12:03
  • 2
    try to use exact version, and move all `implementation ` outside the glide, and move this line apply plugin: 'com.google.gms.google-services' after dependencies closing curly braces, then try rebuild app – Mohamd Ali Mar 27 '18 at 12:05
  • @MohamdAl-Najjar It finally solve the problem when I did changes on build gradle file as suggested and removed android:BackgroundTint:"drawable/microphon.jpg" But now I got another issue, In my android which is 4.1 version the main fragment look like this https://ibb.co/nQNo27 but In Android version 6.1, Card view is not showing instead it appears like this https://ibb.co/ce9e9n. How do I solve this??? – Rishiram Ranabhat Mar 27 '18 at 13:16
  • @RishiramRanabhat i believe you can create same `Menu` with one `CardView` as `ViewHolder` and use `RecyclerView` with `GridLayoutManager` with 2 Columns – Mohamd Ali Mar 27 '18 at 13:21

4 Answers4

3

Use

app:backgroundTint="@drawable/megaphone"

Instead of this

 android:backgroundTint="@drawable/megaphone"

Try this

<android.support.v7.widget.CardView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                app:cardElevation="8dp"
                app:cardCornerRadius="8dp"
                app:backgroundTint="@drawable/megaphone"
                >
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • It finally solve the problem when I did changes on build gradle file as suggested and removed android:BackgroundTint:"drawable/microphon.jpg" But now I got another issue, In my android which is 4.1 version the main fragment look like this https://ibb.co/nQNo27 but In Android version 6.1, Card view is not showing instead it appears like this https://ibb.co/ce9e9n. How do I solve this??? – Rishiram Ranabhat Mar 27 '18 at 13:16
  • @RishiramRanabhat check this https://stackoverflow.com/questions/26728570/android-appcompat-21-elevation/26747592#26747592 – AskNilesh Mar 27 '18 at 13:18
  • @RishiramRanabhat check this https://stackoverflow.com/questions/27599603/cardview-not-showing-shadow-in-android-l – AskNilesh Mar 27 '18 at 13:19
2

You have implemented all dependencies in glide. Try below gradle

Gradle :

dependencies {
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation("com.github.bumptech.glide:glide:4.6.1") {
        exclude group: "com.android.support" 
     }
        implementation 'com.android.support:appcompat-v7:26.+'
        implementation 'com.android.support:support-v4:26.+'
        implementation 'com.android.support:cardview-v7:26.+'
        implementation 'com.android.support:recyclerview-v7:26.+'
        implementation 'com.google.firebase:firebase-messaging:11.8.0'
        implementation 'com.google.gms:google-services:3.1.0'
        implementation 'com.android.support:design:26.+'
        implementation 'de.hdodenhof:circleimageview:2.2.0'

        implementation 'com.theartofdev.edmodo:android-image-cropper:2.5.1'
        implementation 'com.android.support:gridlayout-v7:26.+'
        implementation 'com.github.clans:fab:1.6.2'
        testCompile 'junit:junit:4.12'
        implementation 'com.google.android.gms:play-services-maps:11.8.0'
        implementation 'com.google.firebase:firebase-firestore:11.8.0'
        implementation 'id.zelory:compressor:2.1.0'
        implementation files('libs/libGoogleAnalyticsServices.jar')

    apply plugin: 'com.google.gms.google-services'
}
Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
  • And also change this 26.+ to 26.0.1 – Vidhi Dave Mar 27 '18 at 12:14
  • It finally solve the problem when I did changes on build gradle file as suggested and removed android:BackgroundTint:"drawable/microphon.jpg" But now I got another issue, In my android which is 4.1 version the main fragment look like this https://ibb.co/nQNo27 but In Android version 6.1, Card view is not showing instead it appears like this https://ibb.co/ce9e9n. How do I solve this??? – Rishiram Ranabhat Mar 27 '18 at 13:16
  • Try in manifest – Vidhi Dave Mar 28 '18 at 01:58
1

After looking to your xml code, I found that you forgot to declare the id news and notice which causes this android.view.InflateException.

Solution: Declare these fields to the required ImageView's

Chirag
  • 555
  • 1
  • 5
  • 20
  • Chirag...I'm sorry but stackoverflow cloudn't allowded me to post mor ethen 3000 line of code, so I just only part my xml and rest are same...and I have declared bot news and notices..I doubled checked my xml....but thanks for your kind suggestions. – Rishiram Ranabhat Mar 27 '18 at 12:13
1

try to use app:cardBackgroundColor Instead, i think the tint not working on CardView

OR

for testing issues, try to replace @drawable/megaphone with any colors, maybe the problem inside the megaphone

Mohamd Ali
  • 2,146
  • 4
  • 23
  • 30