Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannont resolve getIntegerInstance

 
John RLee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
John RLee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic