Cannot resolve symbol "NavigationView"

I made a NavigationView inside 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 import line

 import android.support.design.widget.NavigationView 

but it also gives me errors. Any ideas? Could not find a solution on the Internet.

Edit: After adding the dependency specified in Tanis's 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 
+4
source share
2 answers

It looks like you do not have a library included as a Gradle dependency.

Add the following to your build.gradle file:

 dependencies { compile 'com.android.support:design:22.2.1' } 

The error message "Could not find com.android.support:design:22.2.1." means that you probably havenโ€™t installed the latest version of the supported Android repository. Open the SDK Manager and make sure that the "Support for Android Support" and "Support for Android Repository" items in the "Advanced" section are updated.

+18
source

For those who are looking for BottomNavigationView and have introduced this question, you need to have design packages greater than 25

 dependencies { compile 'com.android.support:design:25.0.0' } 
+1
source

All Articles