Results 1 to 5 of 5
  1. #1
    fr0s1yjack is offline Member
    Join Date
    Jun 2011
    Posts
    11
    Rep Power
    0

    Default Problem with parseInt

    Okay guy, I am trying to read in a file and using the StringTokenizer save separate parts to variables. However I need to pull out data which is a string and put it back into an array in int format, I am having problems with the following code:

    Java Code:
    for (int counter = 0; counter  < 32; counter ++) {
                            Integer.parseInt(seats[counter].status);
                            seats[counter].status = st.nextToken();
                 }
                    }
    The error I get is:

    java.lang.NullPointerException

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,993
    Rep Power
    9

    Default

    Without seeing more code (in SSCCE form), all I can say is that either seats[counter] or your st variable is null.

    Also, you aren't storing the int returned from parseInt() anywhere, so that line isn't actually doing anything.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    srid12 is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    store the value of the parseint.
    see Moderator edit: link removed
    Last edited by DarrylBurke; 06-25-2011 at 05:14 PM. Reason: Removed link

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

    Default

    store the value of the parseint.
    java is case sensitive. This should be the value returned by parseInt().

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    Also, read the API for StringTokenizer.
    StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.
    db

Similar Threads

  1. Problem with statement "Integer.parseInt(args[0]);
    By peterfgoossens@gmail.com in forum New To Java
    Replies: 8
    Last Post: 05-17-2011, 04:13 PM
  2. parseInt
    By trefoil in forum New To Java
    Replies: 4
    Last Post: 09-09-2009, 07:12 PM
  3. [SOLVED] Integer.parseInt() problem
    By eggmanpete in forum New To Java
    Replies: 18
    Last Post: 02-15-2009, 04:25 PM
  4. Replies: 11
    Last Post: 01-10-2009, 02:16 AM
  5. Problem with Integer.parseInt()
    By Hevonen in forum New To Java
    Replies: 2
    Last Post: 12-14-2008, 03:41 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
  •