在import语句中获取错误 [英] Getting errors in import statement

查看:139
本文介绍了在import语句中获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,首先我正在处理的项目有两个包,首先是murach.business,其中包含invoiceCalculations.java。其次是murach.forms,其中包含InvoiceForm.java(JFrame)和SwingValidator.java

Okay, first the project I am working on has two packages, first is murach.business which contains invoiceCalculations.java Second is murach.forms which contain InvoiceForm.java(JFrame) and SwingValidator.java

所以,我应该为我从头创建的Invoiceformjava中的murach.business.InvoiceCalculations和java.text.NumberFormat类添加Add import语句。

So, I am supposed to add Add import statements for the murach.business.InvoiceCalculations and java.text.NumberFormat classes in Invoiceformjava that i created from the scratch.

但是,我在编写代码时遇到错误。 netbeans说下面代码的未使用代码:

But, I am getting errors when i code that. netbeans says unused code for the below code:

我是否错误地编写了代码?怎么了?请按正确方向推进。

have i written the code incorrectly? whats wrong? Please push in right direction.

 import murach.business.InvoiceCalculations;
 import java.text.NumberFormat;


推荐答案

未使用的代码并不代表你有语法错误。它只是意味着导入不是必需的,因为该类的当前代码尚未使用导入的类。如果在使用导入类的类中添加代码,则警告将消失。

"Unused code" doesn't mean that you have a syntax error. It just means that the import is not necessary, because the current code of the class doesn't use the imported class yet. If you add code inside the class that uses the imported class, the warning will disappear.

请注意,对于当前的IDE,通常不需要手动添加import语句。您可以在不导入类的情况下使用该类,并使用键盘快捷键(或自动完成)自动添加必要的导入(并删除未使用的导入)。在Netbeans中,命令是Fix Imports(Ctrl-Shift-I)

Note that, with current IDEs, you usually don't bother adding import statements manually. You use the class without importing it, and use a keyboard shortcut (or autocompletion) to add the necessary imports (and remove the unused ones) automatically. In Netbeans, the command is "Fix Imports (Ctrl-Shift-I)"

这篇关于在import语句中获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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