Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Beginner programming- strange problem

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Beginner programming- strange problem

    Hi everyone,
    Sorry if this is blatently obvious but i am new to programming.
    My problem is with this piece of code:

    currEx = in.charAt(currSubStr);

    Java says the following:

    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(String.java:686)
    at AssigOne2011.main(AssigOne2011.java:38)

    I assume this means that the int currSubString is not valid, however i know foor sure that this is 0 seeing as i assign that value one line before the one i am having a problem with.

    Any help would be greatly appreciated, as i am stumped!


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Beginner programming- strange problem

    Are you validating the length of the String before you use charAt()? Maybe the String is not as long as you think it is. If a String's length is 0, it has *no* valid indexes.

Similar Threads

  1. Beginner Problem
    By Melvrick in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 15th, 2011, 01:29 PM
  2. Strange problem printing Unicode characters
    By sophist42 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 29th, 2011, 11:53 AM
  3. Programming beginner
    By LatinaC09 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 15th, 2010, 02:33 PM
  4. Strange launch problem using command prompt
    By Asido in forum Java Theory & Questions
    Replies: 2
    Last Post: September 15th, 2010, 08:52 AM
  5. Strange problem with drawing string
    By Asido in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 26th, 2010, 04:38 PM

Tags for this Thread