aspose file tools*
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
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: 24184
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannont resolve getIntegerInstance