2

While deploying app to phone, the app keeps on crashing with a message that app has stopped. I have already tried looking for an answer on stack overflow but nothing resolves my problem. I cleaned my project, Invalidate and restart, change Api from 28 to 27 as one of the answer also said this. On and all I have tried everything which I could find.

MainActivity.java

 package com.example.panchaat;
 import android.content.Intent;
 import android.os.Bundle;
 import androidx.appcompat.widget.Toolbar;
 import android.view.MenuItem;
 import android.view.View;
 import android.widget.*;
 import androidx.annotation.NonNull;
 import androidx.appcompat.app.ActionBarDrawerToggle;
 import androidx.appcompat.app.AppCompatActivity;
 import androidx.drawerlayout.widget.DrawerLayout;
 import androidx.recyclerview.widget.RecyclerView;
 import com.google.android.material.navigation.NavigationView;
 import com.google.firebase.auth.FirebaseAuth;
 import com.google.firebase.auth.FirebaseUser;
 public class MainActivity extends AppCompatActivity {
    private NavigationView navigationView;
    private ActionBarDrawerToggle actionBarDrawerToggle;
    private DrawerLayout drawerLayout;
    private RecyclerView postList;
    private Toolbar mToolbar;
    private FirebaseAuth mAuth;
 @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
                      }
                     }

build.gradle

      apply plugin: 'com.android.application'

 android {
 compileSdkVersion 28
 defaultConfig {
    applicationId "com.example.panchaat"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
  "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
 }
 buildTypes {
     release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
 'proguard-rules.pro'
      }
  }
  compileOptions {
       targetCompatibility = '1.8'
       sourceCompatibility = '1.8'
  }
   buildToolsVersion = '28.0.3'
 }

 dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'com.android.support:appcompat-v7:28.1.1'
   implementation 'com.android.support:design:28.1.0'
   implementation 'com.android.support.constraint:constraint-layout:1.1.2'
   implementation 'com.google.firebase:firebase-auth:11.0.2'
   implementation 'com.google.android.gms:play-services-auth:11.0.2'
   implementation 'com.google.firebase:firebase-database:11.0.2'
   implementation 'com.google.firebase:firebase-storage:11.0.2'
   implementation 'de.hdodenhof:circleimageview:3.0.0'
   implementation 'com.theartofdev.edmodo:android-image-cropper:+'
   implementation 'com.squareup.picasso:picasso:2.5.2'
   implementation 'com.firebaseui:firebase-ui-database:2.1.1'
   implementation 'androidx.appcompat:appcompat:1.0.2'
   implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
   implementation 'com.android.support:appcompat-v7:28.1.1'
   implementation 'com.android.support:design:28.1.1'
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'com.android.support.test:runner:1.0.2'
   androidTestImplementation 'com.android.support.test.espresso:espresso- 
   core:3.0.2'
   implementation 'com.android.support:support-v13:28.0.0'
   implementation files('support-v13')
   implementation 'com.android.support:support-v4:28.0.0'
   implementation 'com.android.support:support-v13:28.0.0'
   implementation "com.android.support:support-core-utils:28.1.0"
   }
   apply plugin: 'com.google.gms.google-services'

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
 <androidx.drawerlayout.widget.DrawerLayout
    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"
    android:fitsSystemWindows ="true"
    tools:context="com.example.panchaat.MainActivity"
    android:id="@+id/drawer_layout">

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

   <include
   android:id="@+id/main_page_toolbar"
    layout="@layout/app_bar_layout">
   </include>


    <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="634dp"
            android:layout_alignParentStart="true"
            android:layout_marginStart="0dp"
            android:layout_alignParentTop="true"
            android:layout_marginTop="21dp"
            android:id="@+id/main_contaier">

        <androidx.recyclerview.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/all_users_post_list"
                android:layout_alignTop="@+id/main_contaier"
                android:layout_alignStart="@+id/main_contaier"/>
    </FrameLayout>
</RelativeLayout>
<com.google.android.material.navigation.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_marginBottom="3dp"
        app:menu="@menu/navigation_menu"
        android:id="@+id/navigation_view">
 </com.google.android.material.navigation.NavigationView>
 </androidx.drawerlayout.widget.DrawerLayout>

app_bar_layout.xml:

<androidx.appcompat.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
     android:id ="@+id/main_app_bar"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:background ="#3a1c71"
    android:theme ="@style/ThemeOverlay.AppCompat.Dark">
  </androidx.appcompat.widget.Toolbar>

logcat

Caused by: android.view.InflateException: Binary XML file line #2: Binary 
 XML file line #2: Error inflating class 
 android.support.v4.widget.DrawerLayout
 Caused by: android.view.InflateException: Binary XML file line #2: Error 
 inflating class android.support.v4.widget.DrawerLayout
 Caused by: java.lang.ClassNotFoundException: Didn't find class 
 "android.support.v4.widget.DrawerLayout"
Nabeel Ahmed
  • 31
  • 1
  • 4

1 Answers1

-1
Caused by: android.view.InflateException: Binary XML file line #2: Binary 
 XML file line #2: Error inflating class 
 android.support.v4.widget.DrawerLayout
 Caused by: android.view.InflateException: Binary XML file line #2: Error 
 inflating class android.support.v4.widget.DrawerLayout
 Caused by: java.lang.ClassNotFoundException: Didn't find class 
 "android.support.v4.widget.DrawerLayout"

It's because you're mixing Android Support Library and AndroidX in your activity_main.xml:

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

 <!-- This is Android Support Library -->
 <android.support.v4.widget.DrawerLayout
    ...
    android:id="@+id/drawable_layout">

    ...

 <!-- This is AndroidX library -->
 <com.google.android.material.navigation.NavigationView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:layout_marginBottom="3dp"
    app:menu="@menu/navigation_menu"
    android:id="@+id/navigation_view">

</android.support.v4.widget.DrawerLayout>

And it seems that you didn't use any Support library in your dependencies. Hence the error is thrown.

So, change your layout to use the AndroidX view.

For your activity_main.xml, something like this:

<?xml version="1.0" encoding="utf-8"?>
 <androidx.drawerlayout.widget.DrawerLayout
    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="com.example.panchaat.MainActivity"
    android:id="@+id/drawable_layout">

     ...

   <com.google.android.material.navigation.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_marginBottom="3dp"
        app:menu="@menu/navigation_menu"
        android:id="@+id/navigation_view">

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

</androidx.drawerlayout.widget.DrawerLayout>

And for your app_bar_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
     android:id ="@+id/main_app_bar"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:background ="#3a1c71"
    android:theme ="@style/ThemeOverlay.AppCompat.Light">

</androidx.appcompat.widget.Toolbar>

And make sure you also import the correct corresponding view in your Activity.

Please visit Migrating to AndroidX

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • I made the changes as you said , but the problem does not gets resolved – Nabeel Ahmed Aug 16 '19 at 09:50
  • Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.support.v4.widget.DrawerLayout – Nabeel Ahmed Aug 16 '19 at 09:50
  • @NabeelAhmed: Your xml is slightly incorrect, it should be `androidx.drawerlayout.widget.DrawerLayout`. – ישו אוהב אותך Aug 16 '19 at 09:53
  • Please review my edited question I have included the imports I did in MainActivity and also included build.gradle file plus with the editions you previously mentioned. Now what should i do resolve this issue. TIA – Nabeel Ahmed Aug 16 '19 at 10:52