简体   繁体   English

为什么这些进口有误?

[英]Why Are These Imports Errored?

As part of my uni project, I have had to clone a group member's code and work on it myself. 作为我的uni项目的一部分,我不得不克隆一个小组成员的代码并亲自进行处理。 But on the imports included below, they are underlined and I can't seem to know why or how to address this. 但是在下面包括的进口商品中,有下划线的是我的下划线,我似乎不知道为什么或如何解决这个问题。 Netbeans says that these are 'Unused imports'. Netbeans说这些是“未使用的进口”。 I've already tried to Google this but with no luck. 我已经尝试过使用Google,但是没有运气。

What does this mean and how do I fix it? 这是什么意思,我该如何解决? Please bear with me as I am completely new to programming and it's concepts. 请耐心等待,因为我对编程及其概念是全新的。 Thank you. 谢谢。

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import static org.apache.http.HttpHeaders.USER_AGENT;

As the name implies, "Unused import" is a message from the IDE (not directly related to Java) and means that you're not using that class/interface/whatever it is. 顾名思义,“未使用的导入”是来自IDE的消息(与Java没有直接关系),表示您没有使用该类/接口/无论使用什么。 Also, note that this is a warning, not an error. 另外,请注意,这是警告,不是错误。 This means, your code can compile and execute without issues. 这意味着您的代码可以毫无问题地进行编译和执行。

To fix this, just remove the unused import statements. 要解决此问题,只需删除未使用的import语句。

Example of how to raise unused import: 如何提高未使用的导入的示例:

package something;

//this interface is never used in this class
import java.util.List;

public class Example {
    public static void main(String args[]) {
        System.out.println("Hello world");
    }
}

Example of how to fix it: 解决方法示例:

package something;
//removed import java.util.List; since it's not used

public class Example {
    public static void main(String args[]) {
        System.out.println("Hello world");
    }
}

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

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