Disappearing import statement in Android code
I am using "Hello, Android" 1.5& 1.6 with the 2.1 android Java build. I typed:
import android.os.Bundle;
It disappeared as soon as I finished typing!! Help, please.?开发者_如何学JAVA
By default Eclipse hides all import
statements under a single line.
Click the +
button next to the import
you can see and it should show them all.
Settings -> Editor -> General -> Auto Import.
You will find two options.
1. Add unambiguous imports on the fly.
2. Optimize imports on the fly.
When we type any class or annotation name and if the class is unambiguous and it is still not imported then IDE will automatically add the imports for us if Add unambiguous imports on the fly is selected. If the imports are ambiguous then IDE prompts us which class/interface need to add for import statement.
If "Optimize imports on the fly" option is turned on, when you import something then IDE will check whether it is used in the code or not. If the answer is "No" then IDE optimizes the imports and removes it. For solving this issue uncheck the "Optimize imports on the fly "option.
To learn more check the below links,
Remove unused imports in Android Studio
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206223159-Java-import-hiding-disappearing
精彩评论