Reputation: 614
I have just starting working my android studio project in another pc with same android studio version and it automatically makes used import statement as unused in the code and mark evey code related to particular import statement red. How can i fix this issue , its very annoying. but when i run the project ,it works fine without any error.
I have tried all those tricks including deleting .ide ,.gradle and even restarting with invalidate cash ,restard and disabling automatic import as well.
In the below screenshot , android studio just grayout all import statment i am using below and mark all those classes and its related method red in the code. how can i fix this issue
Upvotes: 4
Views: 1922
Reputation: 303
You don't need to import the interface as it is inside the same file.
You can make a separate file for the interface.
Upvotes: 1
Reputation: 2098
MyAppObserver
is unused import because you import it in the same file it's declared. As for others I am not sure because I can't see full file structure.
Upvotes: 3
Reputation: 2214
This happens sometimes. You will need to clean the project. If that doesn't work try invalidate caches/restart. First, go to File, then choose: Invalidate Caches/Restart...
Then this dialog pops up, choose Invalidate and Restart.
Most of the times when IDE doesn't behave as it should, you can try this.
Upvotes: 1
Reputation: 711
Try to clean then rebuild project. If this still exists then close Android studio then re-launch it again. sometimes I face the same situation but it got fixed after clean and rebuild
Upvotes: 1
Reputation: 2576
Your interface of the same name is causing a conflict.
interface MyAppObserver
Rename your interface and the imports should work correctly, and the red marks should go away.
Upvotes: 2