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 import;.

There are numerous questions on SO asking specifically about a particular class.

But how am I supposed to know in which "metapackage" (i.e. in the above example) I can find the class definition ?

I found a base Java list and an Android class index but it seems quite tedious to go back and forth between both lists and having to click on each class to have the full path.

Bonus question : does Android Studio have a shortcut to help finding them ?

3 answers

  • answered 2018-09-25 13:56 TheWanderer

    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.

  • answered 2018-09-25 13:57 Joe

    alt+Enter suggests a list of possible packages.

  • answered 2018-09-25 13:57 Aviral Ahuja

    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