Results 1 to 4 of 4
  1. #1
    aks_saxena is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Question How to get Integer values from Text Field

    I have created a static array of integers and from a dynamic array of text fields i have to get values. If i am using Integer.parseInt it is showing Number Format Exception. I am posting the code .Please help me out.

    for( i=0;i<k;i++)
    {
    jls[i] = new javax.swing.JLabel("Page No."+(i+1));
    jtext[i] = new javax.swing.JTextField(2);

    jDialog1.add(jls[i]);
    jDialog1.add(jtext[i]);
    pages[i]=Integer.parseInt(jtext[i].getText());
    }

    Pages is the Integer array and jtext is the dynamically created array of text fields.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    Please post the exact error message!

    - the text has a leading or trailing spaces? Try Integer.parseInt(jtext[i].getText().trim());
    - the entered number is too big for integer?
    - anything else..? :D

  3. #3
    aks_saxena is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default

    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:470)
    at java.lang.Integer.parseInt(Integer.java:499)

    This error is being shown..

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,764
    Blog Entries
    7
    Rep Power
    21

    Default

    Your dialog wasn't shown on the screen yet so the user wasn't able to type any text in your JTextField so its text was still "" (the empty String as the error message showed).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 14
    Last Post: 01-22-2011, 03:36 PM
  2. An Array of different integer values
    By lithium002 in forum New To Java
    Replies: 7
    Last Post: 12-04-2009, 06:25 AM
  3. resting text field values on jsp page to null......
    By Sachin. in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-27-2009, 03:24 AM
  4. Getting integer values from a JTable
    By zikojam in forum New To Java
    Replies: 1
    Last Post: 12-11-2008, 03:06 PM
  5. Help with define an integer field
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 08:32 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
  •