Results 1 to 2 of 2
- 10-01-2012, 01:28 AM #1
Member
- Join Date
- Jul 2012
- Posts
- 4
- Rep Power
- 0
ArrayIndexOutOfBoundsException Help
I am receiving an ArrayIndexOutOfBoundsException error while I run the below code.
The exception is thrown on this line:Java Code:static String sRomans[] = {"I","V","X","L","C","D","M"}; static int iRomans[] = {1,5,10,50,100,500,1000}; while (pos <= s.length()) { chr = s.substring(pos, 1); p1 = Arrays.asList(sRomans).indexOf(chr); subSum += iRomans[p1]; if(pos != s.length()) { nextChr = s.substring(pos + 1, 1); p2 = Arrays.asList(sRomans).indexOf(nextChr); if (p1 == p2){ pos++; } else { Arabic += subSum; subSum = 0; pos++; } } else { Arabic += subSum; pos++; } }If I remove the follwing code from the loop everything runs like expected.Java Code:subSum += iRomans[p1];
Any help and/or ideas are greatly appreciated.Java Code:chr = s.substring(pos, 1); p1 = Arrays.asList(sRomans).indexOf(chr); subSum += iRomans[p1];
- 10-01-2012, 02:36 AM #2
Re: ArrayIndexOutOfBoundsException Help
Array indexes start at 0 and end at (length - 1). Not at (length).
And please don't flatter yourself that this is an advanced question. I'm moving the thread to New to Java.
Also, you appear to have abandoned the last thread you started. Not the best way to continue to get free help on a forum, that.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
what is ArrayIndexOutOfBoundsException ???
By gauravmanral in forum New To JavaReplies: 6Last Post: 07-16-2011, 07:45 AM -
value of ArrayIndexOutOfBoundsException: 20 ?
By aneuryzma in forum New To JavaReplies: 1Last Post: 03-28-2011, 03:46 PM -
ArrayIndexOutOfBoundsException
By Corey in forum New To JavaReplies: 5Last Post: 02-02-2010, 01:25 AM -
ArrayIndexOutOfBoundsException
By flaskvacuum in forum New To JavaReplies: 6Last Post: 07-14-2009, 05:36 PM -
ArrayIndexOutofBoundsException help
By filly444 in forum New To JavaReplies: 9Last Post: 09-03-2008, 05:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks