为什么将使用的导入语句指定为“未使用的导入语句"?在Android Studio中? [英] Why used import statement is specified as "unused import statement" in Android Studio?

查看:229
本文介绍了为什么将使用的导入语句指定为“未使用的导入语句"?在Android Studio中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android Studio并将其构建为生成已签名的APK ...".而且我遇到了如下错误:未使用的导入语句".

I'm using Android Studio and build as "Generate Signed APK...". And I faced the error, "Unused import statement" like following.

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;  // <- specified as unused ERROR
import android.support.v4.app.FragmentManager;   // <- specified as unused ERROR
import android.support.v4.view.ViewPager;        // <- specified as unused ERROR
import android.util.Log;

public class Main extends FragmentActivity {
...
}

但是我可以很容易地看到在代码中使用了FragmentActivity.我该如何解决?此错误在我的所有代码中均会发生...

But I can easily see FragmentActivity is used in code. How can I fix it? This error happens all over my codes...

推荐答案

这是因为您启用了动态优化导入"功能,该功能会自动删除未使用的导入.您可能还选择了动态添加明确的导入",这会自动添加所需的导入.解决方案是先编写代码,然后观察自动添加您的导入,并在需要时手动添加任何不明确的导入. https://www.jetbrains.com/idea/help/creating-and-optimizing-imports.html?search=optim

This is because you have "Optimize imports on the fly" enabled, which automatically removes unused imports. You likely also have "Add unambiguous imports on the fly" selected, which automatically adds imports you need. The solution is to write the code first, and watch your imports be added automatically, and manually add any ambiguous ones, as they become needed. https://www.jetbrains.com/idea/help/creating-and-optimizing-imports.html?search=optim

如果这不适用于您,或者如果您只是想输入自己的导入语句,则只需在设置>编辑器>自动导入中禁用这些功能.

In the event this does not work for you, or if you simply prefer to enter your own import statements, then simply disable the features in settings > Editor > Auto Import.

这篇关于为什么将使用的导入语句指定为“未使用的导入语句"?在Android Studio中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆