Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – how to resolve cannot find NavigationView

Posted on November 11, 2022 By

Solution 1 :

In build.gradle(app) in ‘dependencies’ add

implementation "com.google.android.material:material:1.2.0-alpha02"

Problem :

I am a beginner in android development and I have encountered some difficulty in using the navigation drawer. I am developing an app with a navigation drawer on the left side. But when I add the navigation view to the xml file of the Main activity, it gives this error message:

Class referenced in the layout file, com.google.android.material.navigation.NavigationView, was not found in the project or the libraries 
Cannot resolve class com.google.android.material.navigation.NavigationView 

This is my code for the Main activity:

package com.hfad.catchat;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

        Fragment fragment = new InboxFragment();
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(R.id.content_frame, fragment);
        ft.commit();
    }
}

This is the xml file of the Main activity:

<?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"
    android_id="@+id/drawer_layout"
    android_layout_width="match_parent"
    android_layout_height="match_parent" >

    <LinearLayout
        android_layout_width="match_parent"
        android_layout_height="match_parent"
        android_orientation="vertical" >

        <include
            layout="@layout/toolbar_main"
            android_id="@+id/toolbar" />

        <FrameLayout
            android_id="@+id/content_frame"
            android_layout_width="match_parent"
            android_layout_height="match_parent" />
    </LinearLayout>

    <com.google.android.material.navigation.NavigationView
        android_id="@+id/nav_view"
        android_layout_width="wrap_content"
        android_layout_height="match_parent"
        android_layout_gravity="start"
        app_headerLayout="@layout/nav_header"
        app_menu="@menu/menu_nav" />
</androidx.drawerlayout.widget.DrawerLayout>

Comments

Comment posted by Gowrishankar

Did you added material dependency in the Gradle file?

Comment posted by Gabriele Mariotti

It is curious the reason why you are suggesting an alpha02 when there is a beta01

READ  [FIXED] java - Why can't I generate a signed APK?
Powered by Inline Related Posts
Android Tags:android, android-studio

Post navigation

Previous Post: [FIXED] android – How to achieve ionic permissions on first load
Next Post: [FIXED] android – How do i put online database into local database

Related Posts

[FIXED] android – kotlin variable type changed in runtime Android
[FIXED] java – Room DAO fails to retrieve data from Database Android
[FIXED] java – NoSuchMethodError: No virtual method setStream in class Landroid/app/WallpaperManager on older Android devices Android
[FIXED] android – Flutter: System UI ‘Location Permissions’ dialog breaks the continuity of the execution of the code? Android
[FIXED] Android device models to actual names Android
[FIXED] How to change the color of element in SVG Image in Android Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme