James Will
James Will

Reputation: 15

Getting errors in import statement

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

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.

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;

Upvotes: 0

Views: 1072

Answers (2)

Sapan Diwakar
Sapan Diwakar

Reputation: 10966

These are not errors but warnings that Netbeans gives you. The code should still compile fine

Upvotes: 2

JB Nizet
JB Nizet

Reputation: 692231

"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.

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)"

Upvotes: 3

Related Questions