tomtom
tomtom

Reputation: 614

Android studio is making used import statement as unused?

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

screenshot

Upvotes: 4

Views: 1922

Answers (5)

Saif
Saif

Reputation: 303

You don't need to import the interface as it is inside the same file.

Just click on the optimize imports

You can make a separate file for the interface.

enter image description here

enter image description here

Upvotes: 1

Nazarii Moshenskyi
Nazarii Moshenskyi

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

Tugay
Tugay

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

1

Then this dialog pops up, choose Invalidate and Restart.

2

Most of the times when IDE doesn't behave as it should, you can try this.

Upvotes: 1

Ramy Ibrahim
Ramy Ibrahim

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

Jens Zalzala
Jens Zalzala

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

Related Questions