I am using NetBeans 3.6 IDE to write some code. I am getting the error message "cannot resolve symbol.." for the getIntergerInstance method. Using the import tool the IDE added the import java.text.NumberFormat which solve a "cannot resolve symbol" error for NumberFormat. Is this a set problem with the IDE or a code issue?
When I check outside the IDE I get java full version "1.4.2_06-b03"
If NumberFormat is resolved shouldn't its methods be resolve as well or are you saying the method is new to java 1.4?
I am going to assume at this point that my machine has java 1.4 but the IDE is using some other java home. I found a project setting to "Enable JDK 1.4 Source", but checking this still dosen't solve the problem.
Joined: Jan 05, 2005
The problem seem to be because NumberFormat is a abstract class and getIntegerInstance() is a static method. The following clears up the problem
JFormattedTextField txtInput1 = new JFormattedTextField(NumberFormat.getIntegerInstance()); or NumberFormat intFormat = NumberFormat.getIntegerInstance(); JFormattedTextField txtInput2 = new JFormattedTextField(intFormat);
So what gives? Is intFormat an instance of an Interger format? So why no "new". Or is intFormat a "pointer" to the Integer format in the NumberFormat class?
Originally posted by John RLee: NumberFormat intFormat = new NumberFormat.getIntegerInstance();
This syntax is illegal. Even if getIntegerInstance() returned a Class object, you'd still need to useBut it doesn't, so don't.
NumberFormat contains several factory methods that return variously configured NumberFormat instances. Looking at the source shows that they all end up calling the generic getInstace(Locale, int choice) factory method which creates and returns a DecimalFormat instance. Thus, intFormat is of type java.text.DecimalFormat.