Reputation: 43
As the title suggests, Auto Import does not seem to work even though I have applied the correct settings.
The posts I've looked up said to uncheck "Optimize imports on the fly" just in case I was automatically adding the imports but then Intellij realized the import was unnecessary so it removed it through optimizing. But as you can see, mine is not on to begin it.
I've also made sure to check mark the Auto Import box from File -> Other Settings -> Default Settings...
I am testing it with a simple program,
I've done these same steps in Android Studio before and everything worked great so I'm at a loss why it does not want to work anymore. In Android Studio, as you typed in a new Object that was unambiguous, it would simply include the imports above. Any help would be much appreciated, thank you!!
Upvotes: 4
Views: 6614
Reputation: 48005
The 'not working' link shows that IntelliJ cannot auto import because ...
The import is not unambiguous; the IDE reports:
java.util.Scanner? (multiple choices ...)
In your preferences you have ticked the option: Add unambiguous imports on the fly
So, for this import Scanner
the IDE seems to be behaving itself correctly. To select a Scanner
import just hit ALT ENTER
, a popup will appear and you can choose from that.
Re this:
I've done these same steps in Android Studio before and everything worked great so I'm at a loss why it does not want to work anymore. In Android Studio, as you typed in a new Object that was unambiguous
That seem to summarise the issue quite well. If the import is unambiguous (i.e. if there is only one possible value for the import) then IntelliJ will auto create the import statement for you but if there are multiple possible values (as is the case for Scanner
) then you have to tell IntelliJ which one you want. Seems to me that IntelliJ is behaving correctly (and consistently with your chosen preferences) for the Scanner
import.
Upvotes: 1