1 2 3 Previous Next 31 Replies Latest reply on Feb 10, 2009 12:12 AM by 843785

    Attempting to give a string array a value?

    843785
      Hello, I need to save the information of the raceTrack, but unable to get the program to continue past this point, spent the entire day researching, any clues

      int amtTracks = Integer.parseInt (in.readLine());

                          String raceTrack[] = new String [amtTracks];
                          int noTracks [] = new int [amtTracks];
                          int trackCode [] = new int [amtTracks];
                          
                          for (int i=0; i<amtTracks; i++){
                               
                     System.out.println ("Please enter track ID number, followed by the name");
                     
                          trackCode = Integer.parseInt (in.readLine ());
                          raceTrack [i] = in.readLine();

      Error: Exception in thread "main" java.lang.NumberFormatException: For input string
        • 1. Re: Attempting to give a string array a value?
          843785
          nvm!

          misread the code!

          Edited by: phdk on 09-02-2009 19:25
          • 2. Re: Attempting to give a string array a value?
            843785
            acestarr wrote:
            Hello, I need to save the information of the raceTrack, but unable to get the program to continue past this point, spent the entire day researching, any clues

            int amtTracks = Integer.parseInt (in.readLine());

                                String raceTrack[] = new String [amtTracks];
                                int noTracks [] = new int [amtTracks];
                                int trackCode [] = new int [amtTracks];
                                
                                for (int i=0; i<amtTracks; i++){
                                     
                           System.out.println ("Please enter track ID number, followed by the name");
                           
                                trackCode = Integer.parseInt (in.readLine ());
                                raceTrack [i] = in.readLine();

            Error: Exception in thread "main" java.lang.NumberFormatException: For input string

            What line generated the exception? This one?
            trackCode  = Integer.parseInt (in.readLine ());
            If so, the first step is to go one step at a time:
            String trackCodeString = in.readLine ();
            System.out.println("trackCodeString is[" + trackCodeString + "]");
            trackCode [i] = Integer.parseInt (trackCodeString );
            Commonsense?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
            • 3. Re: Attempting to give a string array a value?
              843785
              Thanks for the response, but actually the error is in String raceTrack = new String [amtTracks], i think i'm attempting to give the aray a value, but the error from research seems to mean that this can't be done using an int, therefore the value for the array is null

              Screen Dump:

              Welcome to Keep Track of My RaceHorse
              Please enter the number of tracks for which you have data
              2
              Please enter track ID number, followed by the name
              3363
              k
              Please enter track ID number, followed by the name
              Exception in thread "main" java.lang.NumberFormatException: For input string: "k"
              at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
              at java.lang.Integer.parseInt(Integer.java:447)
              at java.lang.Integer.parseInt(Integer.java:497)
              at raceHorsescw02.main(raceHorsescw02.java:56)
              • 4. Re: Attempting to give a string array a value?
                843785
                at raceHorsescw02.main(raceHorsescw02.java:56)
                Whatever line 56 is, it's trying to parse "k" are though it was an integer. M'kay?
                • 5. Re: Attempting to give a string array a value?
                  843785
                  I hear what u'r saying but i don't really understand y this is happening,

                  line 56: trackCode = Integer.parseInt (in.readLine ());
                  • 6. Re: Attempting to give a string array a value?
                    843785
                    acestarr wrote:
                    I hear what u'r saying but i don't really understand y this is happening,

                    line 56: trackCode = Integer.parseInt (in.readLine ()); Ah-ha! Have you tried what I suggested in reply #2? What you are trying to do here is essentially:
                    trackCode  = Integer.parseInt ("k");
                    Is it any surprise this fails?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                    • 7. Re: Attempting to give a string array a value?
                      843785
                      Congratulations on hitting 15,000, DrL.
                      • 8. Re: Attempting to give a string array a value?
                        843785
                        BigDaddyLoveHandles wrote:
                        Congratulations on hitting 15,000, DrL.
                        Right back atcha for 10,000, BigGuy. Take you out to lunch to celebrate?
                        • 9. Re: Attempting to give a string array a value?
                          843785
                          Thx 4 the explanation, be gentle, this is my 3rd mth in java (lol)

                          Sorry for being such a blockhead...but this would mean my for statement is not functioning
                          • 10. Re: Attempting to give a string array a value?
                            843785
                            Dal makhani and poutine for everyone!
                            • 11. Re: Attempting to give a string array a value?
                              843785
                              DrLaszloJamf wrote:
                              BigDaddyLoveHandles wrote:
                              Congratulations on hitting 15,000, DrL.
                              Right back atcha for 10,000, BigGuy. Take you out to lunch to celebrate?
                              Sounds good, but not Chinese. The last time the waiter kept coming onto me. I ordered Chow mein, but he kept saying "You want poke? You want poke?"
                              • 12. Re: Attempting to give a string array a value?
                                843785
                                BigDaddyLoveHandles wrote:
                                DrLaszloJamf wrote:
                                BigDaddyLoveHandles wrote:
                                Congratulations on hitting 15,000, DrL.
                                Right back atcha for 10,000, BigGuy. Take you out to lunch to celebrate?
                                Sounds good, but not Chinese. The last time the waiter kept coming onto me. I ordered Chow mein, but he kept saying "You want poke? You want poke?"
                                Pork. He was asking you if you wanted Pork chow mein.
                                • 13. Re: Attempting to give a string array a value?
                                  843785
                                  DrLaszloJamf wrote:
                                  BigDaddyLoveHandles wrote:
                                  DrLaszloJamf wrote:
                                  BigDaddyLoveHandles wrote:
                                  Congratulations on hitting 15,000, DrL.
                                  Right back atcha for 10,000, BigGuy. Take you out to lunch to celebrate?
                                  Sounds good, but not Chinese. The last time the waiter kept coming onto me. I ordered Chow mein, but he kept saying "You want poke? You want poke?"
                                  Pork. He was asking you if you wanted Pork chow mein.
                                  Oh. If I had known that I could have avoided that awkward scene at his apartment.
                                  • 14. Re: Attempting to give a string array a value?
                                    843785
                                    BigDaddyLoveHandles wrote:
                                    DrLaszloJamf wrote:
                                    BigDaddyLoveHandles wrote:
                                    DrLaszloJamf wrote:
                                    BigDaddyLoveHandles wrote:
                                    Congratulations on hitting 15,000, DrL.
                                    Right back atcha for 10,000, BigGuy. Take you out to lunch to celebrate?
                                    Sounds good, but not Chinese. The last time the waiter kept coming onto me. I ordered Chow mein, but he kept saying "You want poke? You want poke?"
                                    Pork. He was asking you if you wanted Pork chow mein.
                                    Oh. If I had known that I could have avoided that awkward scene at his apartment.
                                    You shouldn't take things so literally. "Lucky Hung Fat D&ouml;ng" is only the name of the restaurant.
                                    1 2 3 Previous Next