Skip to content
Advertisement

Cannot find symbol error in android studio

I’m trying to add fragments to a navigation drawer. But I have the error: cannot find symbol class Fragment.

I added: import android.support.v4.app.Fragment

Also add the fragment object(Fragment fragment)

Where is the mistake? What should I do?

Home.java

JavaScript

build.grandle

JavaScript

I’ve tried to search the web and forums but so far I didn’t find anything helpful.

Thank You so much.

Advertisement

Answer

You are importing Fragment from the old Android Support library (android.support.v<x>) while you’ve configured your project to use AndroidX, so make sure you are importing and using the correct library.

Please visit this link to find the correct import for Fragment.

Replace android.support.v4.app.Fragment with androidx.fragment.app.Fragment.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement