I have a multitude of problems stemming from one central issue: Android Studio isn't recognizing imports.
For example, in my class "ActivityAbout" I have the following import statements:
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;
However, in the IDE (using the first import statement as an example), the import android.content.
is appearing grayed out, and when I hover over it, it says "unused import statement" the Intent
part is appearing red, and when hovering over that, it says "cannot resolve symbol Intent." This occurs for each of my import statements, with the first part being grayed out, and the last part being in red.
Now, this provides a multitude of issues in my code, as anything relating to those import statements appears red and when hovering over it, I get the message "cannot resolve symbol ____"
Here's the kicker- my app still compiles and runs upon opening it on my phone.
I suppose my main issue is that it is incredibly annoying, and auto imports doesn't work either. (I have checked off 'show import popup' in the settings, which is the answer I found for other people having issues with auto import not working). My other concern is that this would make my app ineligible for release on the play store. I'm still looking into the publishing process, so I don't know if that is actually an issue or not.
My question (if no one has an answer for how to fix this) is: is this a problem with the IDE itself or the code?
EDIT: added the other import statements
Launch the Android Studio DMG file. Drag and drop Android Studio into the Applications folder, then launch Android Studio. Select whether you want to import previous Android Studio settings, then click OK.
The R class gets code generated by the IDE and build tools based on our current roster of resources. Each resource gets a corresponding R value based on the type of resource ( R. layout , R.id , R. string , etc.) and the name of the resource ( R.
I just had this issue. I resolved it by clicking File > Invalidate Caches / Restart... > Invalidate and Restart. When Android Studio restarted and indexed all my code again, the issue was gone.
I have no idea what caused it...
I had a similar issue with my project. I resolved it by going to File > Sync with File System
and then closing the project and importing it again
You may need to resync with the gradle again but hopefully it works for you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With