Results 1 to 9 of 9
  1. #1
    vsriram92 is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Question Convert String to int

    Im also facing the same difficulty..

    Im using a textfield to get the values & function say A(int a)

    i get values from user by using getText() method.
    its getting the textfield content as a string.

    i need to pass it to the A(int a).

    i cannot parse tat string to int, so it cant be done..
    Since im connecting with DB in which the input must be integer, i cant pass the values to that function.
    pls help..

  2. #2
    vsriram92 is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Unhappy how to get integer values from jtextfield

    Im using a textfield to get the values & function say A(int a)

    i get values from user by using textfield.getText() method.
    its getting the textfield content as a string.

    i need to pass it to the A(int a).

    i cannot parse tat string to int, so it cant be passed..
    Since im connecting with DB in which the input must be integer, i cant pass the values to that function.
    pls help..

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,447
    Rep Power
    18

    Default Re: Convert String to int

    Moving this to its own thread.
    Thread's cost nothing, and waking a 2 year old thread is not worth it.

    Why can you not parse the String to an int?
    That is the only way of taking a String variable and passing it to a method requiring an int parameter.

    The rest about the DB makes no sense.

    Some code might help clarify what you are trying to do.
    Please do not ask for code as refusal often offends.

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: how to get integer values from jtextfield

    See the Integer class and its parseInt method
    http://docs.oracle.com/javase/6/docs...g/Integer.html

    Edit: I merged the two threads. Please see the forum rules and do not duplicate the same post.
    Last edited by doWhile; 06-27-2012 at 04:17 PM.

  5. #5
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default Re: Convert String to int

    Integer.parseInteger("abc123")
    That would return 123

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,558
    Rep Power
    23

    Default Re: Convert String to int

    @crikey
    What nonsense did you just post? Can you explain what that post is supposed to show?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,447
    Rep Power
    18

    Default Re: Convert String to int

    I'm guessing they didn't try and run that before posting...:)
    Please do not ask for code as refusal often offends.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,558
    Rep Power
    23

    Default Re: Convert String to int

    Or even compile it. Does run imply compilation?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,447
    Rep Power
    18

    Default Re: Convert String to int

    Oh yes, it's parseInt isn't it?
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Replies: 3
    Last Post: 02-10-2012, 06:26 PM
  2. How to convert a string into a BigInteger
    By valery in forum New To Java
    Replies: 4
    Last Post: 09-13-2011, 01:32 PM
  3. Hot to convert string to int ????
    By java_no1 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-07-2011, 07:40 AM
  4. convert string to a date
    By exose in forum New To Java
    Replies: 10
    Last Post: 03-14-2011, 12:12 PM
  5. convert obj to string
    By isme in forum New To Java
    Replies: 11
    Last Post: 06-14-2010, 10:54 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
  •