Skippy le Grand Gourou
Skippy le Grand Gourou

Reputation: 7694

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 java.io.File;.

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 ?

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 ?

Upvotes: 0

Views: 533

Answers (3)

Aviral Ahuja
Aviral Ahuja

Reputation: 215

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

Upvotes: 1

Joe
Joe

Reputation: 341

alt+Enter suggests a list of possible packages.

Upvotes: 2

TheWanderer
TheWanderer

Reputation: 17834

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.

Upvotes: 3

Related Questions