This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes cannont resolve getIntegerInstance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cannont resolve getIntegerInstance" Watch "cannont resolve getIntegerInstance" New topic
Author

cannont resolve getIntegerInstance

John RLee
Greenhorn

Joined: Jan 05, 2005
Posts: 3
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?

import java.awt.event.*;
import java.awt.*;
import java.text.NumberFormat;
import javax.swing.*;

public class UConfig extends JFrame {

NumberFormat intFormat = new NumberFormat.getIntegerInstance();
JFormattedTextField txtInput1 = new JFormattedTextField(intFormat);

....}
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch!

The method you're trying to call was introduced in JDK 1.4; perhaps you're using JDK 1.3 or earlier as your target JDK?


[Jess in Action][AskingGoodQuestions]
John RLee
Greenhorn

Joined: Jan 05, 2005
Posts: 3
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.
John RLee
Greenhorn

Joined: Jan 05, 2005
Posts: 3
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?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
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.
 
jQuery in Action, 2nd edition
 
subject: cannont resolve getIntegerInstance
 
Similar Threads
Pass by ref- pgm err
MIA NumberFormat class
Static Doubly Linked Lists....
Help with currency symbol
Gui is running fine, don't know exactly how to code