IndexOutOfBoundsException
in
Programming Questions
•
2 years ago
Hello all,
I have some example code:
public static int ego = 0;
void setup () {
int haspreface = 0; //linked to ControlP5 checkbox...!
for (ego = ego ; ego <= 10 ; ++ego) {
println("ego is: " + ego);
int superego = 1;
if (haspreface == 0) {
superego = ego + 1;
} else if (haspreface == 1) {
superego = ego + 2;
}
println("superego is: " + superego);
}
}
Which gives me the output I need. When I attempt to translate it into a real program, ergo:
Elements tocitems = toc.select("[id^=ch]");
for (ego = ego ; ego <= tocitems.size() ; ++ego) {
Element tocitem = tocitems.get(ego);
println("Count is: " + ego);
int superego = 1;
if (haspreface == 0) {
superego = ego + 1;
} else if (haspreface == 1) {
superego = ego + 2;
}
println("mbp_toc_ is: " + superego);
tocitem.wrap("a href=\"paper1.html#mbp_toc_" + superego + "\"></a>");
}
I get an IndexOutOfBoundsException on the line "Element tocitem = tocitems.get(ego);" - now, its only early here, and I may be suffering from lack of sleep and caffeine, but I'm failing to see why. Yes, the program must be asking for a "ch x" that isn't there, so how do I get around that?
Thanks!
I have some example code:
public static int ego = 0;
void setup () {
int haspreface = 0; //linked to ControlP5 checkbox...!
for (ego = ego ; ego <= 10 ; ++ego) {
println("ego is: " + ego);
int superego = 1;
if (haspreface == 0) {
superego = ego + 1;
} else if (haspreface == 1) {
superego = ego + 2;
}
println("superego is: " + superego);
}
}
Which gives me the output I need. When I attempt to translate it into a real program, ergo:
Elements tocitems = toc.select("[id^=ch]");
for (ego = ego ; ego <= tocitems.size() ; ++ego) {
Element tocitem = tocitems.get(ego);
println("Count is: " + ego);
int superego = 1;
if (haspreface == 0) {
superego = ego + 1;
} else if (haspreface == 1) {
superego = ego + 2;
}
println("mbp_toc_ is: " + superego);
tocitem.wrap("a href=\"paper1.html#mbp_toc_" + superego + "\"></a>");
}
I get an IndexOutOfBoundsException on the line "Element tocitem = tocitems.get(ego);" - now, its only early here, and I may be suffering from lack of sleep and caffeine, but I'm failing to see why. Yes, the program must be asking for a "ch x" that isn't there, so how do I get around that?
Thanks!
1