Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol 'NavigationView'

I made a NavigationView inside a DrawerLayout in an XML file - but when I try to initialize it in Java I get this error.

// DrawerLayout initialises fine
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
// Cannot resolve symbol 'NavigationView'
NavigationView navView = (NavigationView) findViewById(R.id.navigation_view);

I tried adding the import line

import  android.support.design.widget.NavigationView

but this is also giving me errors. Any ideas? Haven't been able to find a solution online.

Edit: After adding dependency given in Tanis' answer, I get these errors

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not find com.android.support:design:22.2.1.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/support/design/22.2.1/design-22.2.1.pom
         https://jcenter.bintray.com/com/android/support/design/22.2.1/design-22.2.1.jar
         https://repo1.maven.org/maven2/com/android/support/design/22.2.1/design-22.2.1.pom
         https://repo1.maven.org/maven2/com/android/support/design/22.2.1/design-22.2.1.jar
         file:/C:/Users/SV_Laptop03/AppData/Local/Android/sdk/extras/android/m2repository/com/android/support/design/22.2.1/design-22.2.1.pom
         file:/C:/Users/SV_Laptop03/AppData/Local/Android/sdk/extras/android/m2repository/com/android/support/design/22.2.1/design-22.2.1.jar
         file:/C:/Users/SV_Laptop03/AppData/Local/Android/sdk/extras/google/m2repository/com/android/support/design/22.2.1/design-22.2.1.pom
         file:/C:/Users/SV_Laptop03/AppData/Local/Android/sdk/extras/google/m2repository/com/android/support/design/22.2.1/design-22.2.1.jar
     Required by:
         MyApp:app:unspecified  
like image 271
HarryBalls Avatar asked Jul 28 '15 16:07

HarryBalls


1 Answers

If you're using AndroidX, Use:

implementation 'com.google.android.material:material:1.0.0'

And in you're layout resource file:

<com.google.android.material.navigation.NavigationView
...
...
/>
like image 125
Javad Arjmandi Avatar answered Oct 05 '22 02:10

Javad Arjmandi