nickerb2's Profile User Rating: -----

Reputation: 0 Apprentice
New Members
Active Posts:
10 (0.01 per day)
22-February 13
Profile Views:
Last Active:
User is offline Mar 14 2013 08:10 AM

Previous Fields

Dream Kudos:
Icon   nickerb2 has not set their status

Posts I've Made

  1. In Topic: Syntax error in switch statement

    Posted 14 Mar 2013

    View Postpbl, on 14 March 2013 - 08:07 AM, said:

        Scanner kbReader = new Scanner(;  
        Scanner kbReader1 = new Scanner(;  
        Scanner kbContinue = new Scanner(;  

    When you have a phone conversation with a friend do you hangup and redial after each sentence ?
    Have a single channel assigned to at a time and use it every time

    I use nextLine with one and the other two im honestly not sure why i have two. :D
  2. In Topic: imbedding arrays, how to

    Posted 12 Mar 2013

    Okay thanks! and is it possible to not be limited just to holding ints and strings in one array,
    n say i was writing a program where I wanted to type in an employe's employe number and then it would come up with their name and how many hours they have worked? So the out put would be something like

    ENTER EMPLOYE #: (user enters number)2


    <the hours would be put in at the end of each work day or something and would stay in an array>
  3. In Topic: array, StringIndexOutOfBoundsException

    Posted 6 Mar 2013

    View Postpbl, on 06 March 2013 - 02:10 PM, said:

    Obviously the user simply enter a <ENTER> and the String length is 0 so getCharAt(0) fails

    And why 3 Scanner assigned to ?
    When you talk on the phone with a friend do you hang up the phone and redial at each sentence ? Same thing here. Have only one Scanner with one channel assigned to

    Well, for one reason thats all ive been taught, and two i beleive because i have all three scanners accepting input they should all be (, correct?

    View Postjon.kiparsky, on 06 March 2013 - 09:29 AM, said:


    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(
    at menuW1.main(

    Ah, thank you. This is useful. So you're trying to access the first character of some String, and it's out of bounds. This means that there's nothing in that String. This is happening at line 70 of your program, which is:

    choice = getChoice.charAt(0);

    So what is getChoice, and how did it get that way? Ah, this is a classic one - it's actually not likely you'd figure this out on your own.

    What is happening here is that the Scanner is playing you false. There's a subtle not-exactly-bug-but-not-what-you-expect in the "convenience" methods of Scanner which always trips people up.

    The nextInt method calls next() to get a token and then tries to parse that token as an int. If it manages to do so, it returns the int, otherwise and exception is thrown. So far, so good, but what you don't realize is that this only takes one token from the line you entered. The line you entered was something like 5\n, and the next() call took only the 5 part. The \n is still there.
    Now when you call nextLine(), that grabs everything up to the next newline character, discards the newline, and returns the rest. This means you get \n, minus the "\n" part: the result is "". So you have a String of length zero, and hence your exception.

    To kill this, call nextLine() and discard the result after you call nextInt(), if you're going to call a nextLine() on that scanner.

    Ugly, I know. I usually just avoid the "convenience" methods and parse the input myself - easier that way, I find.

    wow, i honestly cant believe mixed a "nextLine()" with a "nextInt()"

My Information

Member Title:
New D.I.C Head
Age Unknown
Birthday Unknown

Contact Information

Click here to e-mail me


nickerb2 hasn't added any friends yet.


nickerb2 has no profile comments yet. Why not say hello?