0

I've been making a drawer menu for my home activity, but everytime i tried to run it, it always shows this exception :

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rplgdc.rekrutmenrpl/com.rplgdc.rekrutmenrpl.Activity.HomeActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class android.support.design.widget.NavigationView

I've been reading previous threads, and mostly it was caused by the appcompat and design library in the gradle doesn't match. But i've checked mine and it's matched from one and other.

Here's a few codes that i have.

activity_home.xml file

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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:id="@+id/lyt_parent_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start"
    tools:context=".Activity.HomeActivity">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/home_main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/menu_drawer"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="false"
        app:headerLayout="@layout/layout_menu_header"
        app:itemIconTint="@color/grey_40"
        app:itemTextColor="@color/grey_90"
        app:menu="@menu/item_drawer_menu"/>

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

HomeActivity.java file

package com.rplgdc.rekrutmenrpl.Activity;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.rplgdc.rekrutmenrpl.Adapter.TodaysInputAdapter;
import com.rplgdc.rekrutmenrpl.R;

import java.util.ArrayList;

public class HomeActivity extends AppCompatActivity {
    private static final String TAG = "HomeActivity";

    private Toolbar toolbar;

    private RecyclerView rv;
    private TodaysInputAdapter rvAdapter;

    private LinearLayout allInputs;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_update);

        initToolbar();

        allInputs= findViewById(R.id.btn_all_inputs);
        allInputs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(HomeActivity.this, InputsListActivity.class));
            }
        });

        rv = findViewById(R.id.rv_todays_input);
        rv.setHasFixedSize(true);
        rv.setLayoutManager(new LinearLayoutManager(this));

        rvAdapter = new TodaysInputAdapter(dummyData(), this, 0);
        rv.setAdapter(rvAdapter);

        initNavigationMenu();
    }

    private void initToolbar(){
        toolbar = findViewById(R.id.toolbar_home);
        setSupportActionBar(toolbar);
    }

    private void initNavigationMenu() {
        NavigationView navigationView = findViewById(R.id.menu_drawer);
        final DrawerLayout drawer= findViewById(R.id.lyt_parent_drawer);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
                R.string.navigation_drawer_open, R.string.navigation_drawer_close){
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
            }
        };
        drawer.setDrawerListener(toggle);
        toggle.syncState();
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                Toast.makeText(getApplicationContext(), item.getTitle() + " selected", Toast.LENGTH_SHORT).show();
                drawer.closeDrawers();
                return true;
            }
        });

        drawer.openDrawer(GravityCompat.START);
    }

    private ArrayList<String> dummyData(){
        // just a code for returning a local data for the recycler view
    }
}

My Gradle dependencies

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:support-v13:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-vector-drawable:27.1.1'

If you want more of my codes i will provide it for you to see, any help would be appreciated.

cleanrun
  • 549
  • 6
  • 20

1 Answers1

0

it looks like in file activity_home.xml you are refering to same file. try to remove below line and try to build app:

<include layout="@layout/activity_home"/>
Lukas Novicky
  • 921
  • 1
  • 19
  • 44
  • welp sorry for the mistake, that is actually referring for the main content file. i don't think it is caused by that line. i've edited my post i hope it doesn't add more confusion. my bad – cleanrun Jan 04 '19 at 08:38