简体   繁体   English

Android Studio无法识别导入语句

[英]Android Studio not recognizing import statements

I have a multitude of problems stemming from one central issue: Android Studio isn't recognizing imports. 我有一个问题源于一个核心问题:Android Studio无法识别导入。

For example, in my class "ActivityAbout" I have the following import statements: 例如,在我的类“ActivityAbout”中,我有以下import语句:

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. 但是,在IDE中(以第一个import语句为例), 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." 出现灰色,当我将鼠标悬停在它上面时,它显示“未使用的导入语句”, 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 ____" 现在,这在我的代码中提供了大量问题,因为与这些import语句相关的任何内容都显示为红色,当将鼠标悬停在它上面时,我收到消息“无法解析符号____”

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. 我的另一个顾虑是,这会使我的应用程序没有资格在Play商店发布。 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? 我的问题(如果没有人对如何解决这个问题有答案)是:这是IDE本身或代码的问题吗?

EDIT: added the other import statements 编辑:添加其他导入语句

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. 当Android Studio重新启动并再次索引我的所有代码时,问题就消失了。

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 我通过转到File > Sync with File System然后关闭项目并再次导入它来解决它

You may need to resync with the gradle again but hopefully it works for you 您可能需要再次与gradle重新同步,但希望它适合您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM