Solved

Double.parseDouble behavior

Posted on 2004-04-02
7
390 Views
Last Modified: 2010-03-31
this is something I don't get...

I declared like this:
minXSinTField = new JTextField("0.0", 4);

and then I am using this func to test input validation.
isValidInput(minXSinTField);

This is the func.
  public boolean isValidInput(JTextField tf) {
    boolean result = true;
    try {
      Double.parseDouble(tf.getText());
      result = true;
      System.out.println("in try section");
      System.out.println(result);
    }
    catch (NumberFormatException ex) {
      result = false;
      System.out.println("in  catch section");
      System.out.println(result);
    }
    System.out.println("before return;");
    System.out.println(result);
    return result;
  }

Now, when I enter any string this func returns true.
From other pane's textfields, when I enter string this func returns false.

I don't know why...
0
Comment
Question by:dkim18
  • 3
  • 3
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10741405
Please post input
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10741411
Hi dkim18,


Try this:

  public boolean isValidInput(JTextField tf) {
    try {
      Double.parseDouble(tf.getText());
      return true;
    }
    catch (Exception ex) {
      return false;
    }
  }
0
 

Author Comment

by:dkim18
ID: 10741772
Webstorm,

when I entered string, it still returns true...

CHEJ,

minXSinTField = new JTextField("0.0", 4);

0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 13

Accepted Solution

by:
Webstorm earned 125 total points
ID: 10741858
Display the value returned by getText() :

  public boolean isValidInput(JTextField tf) {
    try {
      System.out.println("Input is ("+tf.getText()+")");
      Double.parseDouble(tf.getText());
      return true;
    }
    catch (Exception ex) {
      return false;
    }
  }
0
 

Author Comment

by:dkim18
ID: 10741929
when I enter string "input"
the outcome was:

Input is (0.0)
0
 

Author Comment

by:dkim18
ID: 10741950
I found error.
I am sharing same private members for two panes...
that was why...

thanks anyway,
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10742041
:-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 42
servlet filter example 37 72
How to execute a Python program and gather return output in Java 2 40
servlet and mdb, jms error 1 33
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question