How do I find a specific Java class definitions?
I am getting my hands on an Android application project. The compiler often complains that it "cannot find symbol class" or variable, because their definition has to be imported explicitely.
E.g. if I need the
File class I have to
There are numerous questions on SO asking specifically about a particular class.
But how am I supposed to know in which "metapackage" (i.e.
java.io in the above example) I can find the class definition ?
Bonus question : does Android Studio have a shortcut to help finding them ?
This should answer both questions.
You can simply click on the declaration you've made and hit Alt+Enter. This will bring up a context menu, with either an "Import..." option or a list of possible imports. Simply use your arrow keys to select the proper one and then hit Enter to import it.
The menu will tell you the package that class is in, and you won't have to know it beforehand.
alt+Enter suggests a list of possible packages.
Place your cursor on the class u wish to import and press ctrl+space and you will get suggestions and just click on the correct option , it will be imported automatically
Refer to below link for all shortcuts in android studio https://developer.android.com/studio/intro/keyboard-shortcuts