I have an array with the format province;capital.
provArray = new String[] { "Alberta;Edmonton", "British Columbia;Victoria", "Manitoba;Winnipeg", "New Brunswick:Fredericton",
"Newfoundland and Labrador;St.John's", "Nova Scotia;Halifax", "Ontario;Toronto", "Prince Edward Island;Charlottetown",
"Quebec;Quebec City", "Saskatchewan;Regina", "Northwest Territories;Yellowknife", "Nunavut;Iqaluit", "Yukon;Whitehorse",
"Alabama;Montgomery", "Alaska;Juneau", "Arizona;Phoenix", "Arkansas;Little Rock", "California;Sacramento", "Colorado;Denver",
"Connecticut;Hartford"};
Then I have a for loop that separates the provinces from the capital (before and after the ";"). Yet for some reason, I get the error, java.lang.ArrayIndexOutOfBoundsException: length=1; index=1.
for(int k = 0; k < bonusArray.length; k++){
String[] split = bonusArray[k].split(";");
String prov = split[0];
String cap = split[1];
if(prov.equals(answer)){
bonusAnswer = cap;
}
}
How can I fix this error?
Edit: Fixed, I had accidentally put : instead of ; for one of my array items.
Province, which stores the name and capital as separate fields, that you initialize likenew Province("Alberta", "Edmonton").