StringArrayIndexOutOfBounds
in
Programming Questions
•
6 months ago
Hello (again)!
When I run this code, I'm getting a StringArrayIndexOutOfBounds at 2 error. While I know what this means, I'm not sure what in the code is causing it to go out of bounds.
When I run this code, I'm getting a StringArrayIndexOutOfBounds at 2 error. While I know what this means, I'm not sure what in the code is causing it to go out of bounds.
I'd appreciate any help; thank you!
The problematic line is bolded.
The problematic line is bolded.
***
int a, e, i, o, u, y;
PImage bckgrnd;
void setup () {
size (400, 800);
bckgrnd = loadImage ("FinalProjectBackground.jpg");
image (bckgrnd, 0, 0);
}
void draw()
{
a = 0;
e =0;
i =0;
u = 0;
y = 0;
String[] lines;
lines = loadStrings("VanGoghLetter.txt");
for (int k = 0; k < lines.length; k++) {
String[] words = split(lines[k], ' ');
for (int i = 0; i< words.length; i++) {
for (int j = 0; j<words.length; j++) {
char letters = words[i].charAt(j);
if (letters == 'a' || letters == 'A')
{
a++;
}
if (letters == 'e' || letters == 'E')
{
e++;
}
if (letters == 'i' || letters == 'I')
{
i++;
}
if (letters == 'o' || letters == 'O')
{
o++;
}
if (letters == 'u' || letters == 'U')
{
u++;
}
if (letters == 'y' || letters == 'Y')
{
y++;
}
}
}
}
int totala = a;
int totale = e;
int totali = i;
int totalo = o;
int totalu = u;
int totaly = y;
astar [] astars = new astar [a];
estar [] estars = new estar [e];
istar [] istars = new istar [i];
ostar [] ostars = new ostar [o];
ustar [] ustars = new ustar [u];
ystar [] ystars = new ystar [y];
for (int i=0; i < a ; i++) {
astars[i] = new astar();
astars[i].drawastar();
}
for (int i=0; i < e ; i++) {
estars[i] = new estar();
estars[i].drawastar();
}
for (int j=0; j < i ; j++) {
istars[j] = new istar();
istars[i].drawastar();
}
for (int i=0; i < o ; i++) {
ostars[i] = new ostar();
ostars[i].drawastar();
}
for (int i=0; i < u ; i++) {
ustars[i] = new ustar();
ustars[i].drawastar();
}
for (int i=0; i < y ; i++) {
ystars[i] = new ystar();
ystars[i].drawastar();
}
}
1