for (String cName : lnames)
{
for(int i = 0; i < uniquelname.length; i++)
{
if(cName.equals(uniquelname[i]))
{
//we want it to increase counter one
sCount[i]++;
itIsThere = true;
break;
}else{
itIsThere = false;
}
if (!itIsThere)
{
uniquelname[dynamicSize] = cName;
dynamicSize++;
}
}
for(int i = 0; i<sCount.length; i++)
{
if (maxCount < sCount[i])
{
maxCount = sCount[i];
maxIndex = i;
}
}
THE ERROR MESSAGE IM RECEIVING IS
WE IN THERECormier 1WE IN THERECormier 2Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at Homework.main(Homework.java:48)
Re: Java programming help!! It compiles but wont run with out one error
THE ERROR MESSAGE IM RECEIVING IS
WE IN THEREWhiter 1WE IN THEREWhite 2Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at Homework.main(Homework.java:48)
Re: Java programming help!! It compiles but wont run with out one error
No, what you are not understanding is that you need to understand what the problem is so you can fix it yourself.
Now I've told you what the problem is ie you are trying to access the element at index 5 of the array when the max allowable index is 4. So you now have to look at the code and find out why maxIndex is 5.
A good way of debugging this type of problem is to add some System.out.println("") statements and output the value of variables and various places so you can see how they are changing. I would help further but you haven't posted your code in code tags so it's difficult to read.
Re: Java programming help!! It compiles but wont run with out one error
You're accusing me of being rude! so lets just analyze your posts:
You posted without reading the forum guides - you didn't use code tags.
You typed part of your post in upper case letters - that is considered to be shouting.
You basically ignored my reply:
You neither went back and edited your post to include code tags, asked how to use them nor apologised for not using them.
You made no discernible effort to solve the problem even though I told you what it was.
If all you wanted was to be told how to fix the problem and not how to debug it yourself, maybe you should change your user name from "teachme" to "tellme"
Last edited by keang; October 19th, 2012 at 12:49 PM.
Bookmarks