Results 1 to 2 of 2
  1. #1
    noobster is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default Getting show dialog box to generate properly

    Hi, I have a feeling I'm gonna feel pretty dumb when someone helps me with this. I'm really really new and am probably over my head with this stuff but my determination to learn is relentless. I have get the user to type in their phone number in the dialog box and show their number in this format nnn nnn nnnn with spaces but i should assume whenever they type it in that it will be written like so: nnn-nnn-nnnn. Everytime I try I get thrown this exception

    --------------------Configuration: <Default>--------------------
    Exception in thread "main" java.lang.NumberFormatException: For input string: "nnn-nnn-nnnn"
    at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1224)
    at java.lang.Double.parseDouble(Double.java:510)
    at Chapter3Question66.main(Chapter3Question66.java:16 )

    Process completed.


    any help would be greatly appreciated.
    p.s. here is a copy of what i've written:

    /* Chapter 3 Question 66
    * V. H.
    */

    import javax.swing.JOptionPane;


    public class Chapter3Question66
    {
    public static void main( String [] args)
    {


    String input = JOptionPane.showInputDialog( null, "Please enter your telephone number" );

    Double number = Double.parseDouble( input );

    JOptionPane.showMessageDialog( null, " Your telephone number is " + number );


    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,900
    Rep Power
    25

    Default

    Read the API doc for the method: parseDouble()
    What kind of data will it accept without a problem?
    What kind of Exceptions does it throw if the input is wrong?

    You need to use another technique to parse the input String to extract the data in the format you want it in.

    What formats can the user enter the input in?
    For each one you need to write specific code to extract the data you want.

Similar Threads

  1. show Message Dialog
    By akritc in forum AWT / Swing
    Replies: 7
    Last Post: 06-10-2010, 03:49 PM
  2. Replies: 3
    Last Post: 05-27-2010, 11:54 AM
  3. Replies: 0
    Last Post: 03-05-2010, 05:21 AM
  4. show Confirm Perspective Switch dialog box
    By mostafa in forum Eclipse
    Replies: 0
    Last Post: 11-22-2008, 12:47 PM
  5. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 07:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •