Full ERROR code:
IndexOutOfBoundsException: Index: 109, Size: 88
Could not run the sketch (Target VM failed to initialize).
So im having a problem with my program/project. I am a bit new, so if you have any other suggestions as to how i can improve please tell.
What i think it is:
I think its a problem with my Edge. I can normally run the sketch without the code
edges.add( new Edge((Node1)nodes1.get(56), (Node1)nodes1.get(55)));
edges.add( new Edge((Node1)nodes1.get(55), (Node1)nodes1.get(69)));
edges.add( new Edge((Node1)nodes1.get(55), (Node1)nodes1.get(109)));
The problem comes when i have id nodes 100+
Code:
import java.util.List;
ArrayList nodes1;
ArrayList edges;
PImage img;
void setup(){
size(1920,1080);
img = loadImage("kort.png");
nodes1 = new ArrayList();
edges = new ArrayList();
//1 , 2 , 3 , 4 , 5
nodes1.add(new Node1(1065, 803, 0)); nodes1.add(new Node1(1000, 755, 1)); nodes1.add(new Node1(950, 698, 2)); nodes1.add(new Node1(874, 688, 3)); nodes1.add(new Node1(806, 638, 4));
//6, 7, 8, 9, 10
nodes1.add(new Node1(762, 579, 5)); nodes1.add(new Node1(778, 567, 6)); nodes1.add(new Node1(769, 498, 7)); nodes1.add(new Node1(772, 446, 8)); nodes1.add(new Node1(833, 431, 9));
//11, 12, 13, 14, 15
nodes1.add(new Node1(782, 373, 10)); nodes1.add(new Node1(818, 412, 11)); nodes1.add(new Node1(793, 384, 12)); nodes1.add(new Node1(893, 499, 13)); nodes1.add(new Node1(852, 564, 14));
//16, 17, 18, 19 , 20
nodes1.add(new Node1(967, 588, 15)); nodes1.add(new Node1(1019, 625, 16)); nodes1.add(new Node1(1082, 669, 17)); nodes1.add(new Node1(1122, 696, 18)); nodes1.add(new Node1(1109, 710, 19));
//21,22,23,24,25
nodes1.add(new Node1(1079, 681, 20)); nodes1.add(new Node1(1027, 774, 21)); nodes1.add(new Node1(1087, 752, 22)); nodes1.add(new Node1(1182, 703, 23)); nodes1.add(new Node1(1131, 680, 24));
//26, 27, 28, 29, 30
nodes1.add(new Node1(1090, 660, 25)); nodes1.add(new Node1(771, 387, 26)); nodes1.add(new Node1( 955, 399, 27)); nodes1.add(new Node1( 885, 320, 28)); nodes1.add(new Node1(766, 361, 29));
//31, 32, 33, 34, 35
nodes1.add(new Node1( 782, 300, 30)); nodes1.add(new Node1( 813, 247, 31)); nodes1.add(new Node1( 831, 370, 32)); nodes1.add(new Node1( 936, 433, 33)); nodes1.add(new Node1( 774, 686, 34));
//36, 37, 38, 39, 40
nodes1.add(new Node1( 908, 745, 35)); nodes1.add(new Node1( 927, 694, 36)); nodes1.add(new Node1( 1036, 572, 37)); nodes1.add(new Node1( 1097, 514, 38)); nodes1.add(new Node1(1042 , 459, 39));
//41, 42, 43, 44, 45
nodes1.add(new Node1( 1050, 334, 40)); nodes1.add(new Node1( 1010, 316, 41)); nodes1.add(new Node1( 996, 306, 42)); nodes1.add(new Node1( 981, 224, 43)); nodes1.add(new Node1( 973, 192, 44));
//46, 47, 48, 49, 50
nodes1.add(new Node1( 953, 157, 45)); nodes1.add(new Node1(1155, 572, 46)); nodes1.add(new Node1(1192, 601, 47)); nodes1.add(new Node1(1258, 471, 48)); nodes1.add(new Node1(1235, 642, 49));
//51, 52, 53, 54, 55
nodes1.add(new Node1(1079, 825, 50)); nodes1.add(new Node1(1055, 828, 51)); nodes1.add(new Node1(1053, 847, 52)); nodes1.add(new Node1(1047, 873, 53)); nodes1.add(new Node1(1093, 847, 54));
//56, 57, 58, 59, 60
nodes1.add(new Node1(1053, 923, 55)); nodes1.add(new Node1(1064, 949, 56)); nodes1.add(new Node1(981, 836, 57)); nodes1.add(new Node1(935, 818, 58)); nodes1.add(new Node1(890, 794, 59));
//61, 62, 63, 64, 65
nodes1.add(new Node1(1058, 250, 60)); nodes1.add(new Node1(1014, 188, 61)); nodes1.add(new Node1(1035, 178, 62)); nodes1.add(new Node1(902, 213, 63)); nodes1.add(new Node1(852, 284, 64));
//66, 67, 68, 69, 70
nodes1.add(new Node1(1020, 115, 65)); nodes1.add(new Node1(1139, 328, 66)); nodes1.add(new Node1(956, 763, 67)); nodes1.add(new Node1(1233, 401, 68)); nodes1.add(new Node1(1077, 909, 69));
//71, 72, 73, 74, 75
nodes1.add(new Node1(1105, 798, 70)); nodes1.add(new Node1(1133, 757, 71)); nodes1.add(new Node1(1294, 596, 72)); nodes1.add(new Node1(1321, 591, 73)); nodes1.add(new Node1(1351, 562, 74));
//Destination Nodes
//1
nodes1.add(new Node1(1115, 874, 100));
//2
nodes1.add(new Node1(1155,732, 101));
//3
nodes1.add(new Node1(939, 756, 102));
//4
nodes1.add(new Node1(1205, 400, 103));
//5
nodes1.add(new Node1(1079, 250, 104));
//6
nodes1.add(new Node1(893, 307, 105));
//7
nodes1.add(new Node1(808, 255, 106));
//8
nodes1.add(new Node1(767, 383, 107));
//9
nodes1.add(new Node1(1335, 540, 108));
//10
nodes1.add(new Node1(1044, 895, 109));
//11
nodes1.add(new Node1(1071, 973, 110));
//12
nodes1.add(new Node1(819, 619, 111));
//13
nodes1.add(new Node1(894, 523, 112));
//EDGES
//Start route
edges.add( new Edge((Node1)nodes1.get(56), (Node1)nodes1.get(55))); edges.add( new Edge((Node1)nodes1.get(55), (Node1)nodes1.get(69)));
edges.add( new Edge((Node1)nodes1.get(55), (Node1)nodes1.get(109)));
}
void draw(){
background(0);
image(img, 0,0);
textSize(26);
// text( "x: " + mouseX + " y: " + mouseY, mouseX + 2, mouseY );
for(int i=0; i<nodes1.size(); i++){
Node1 n = (Node1) nodes1.get(i);
n.display();
}
for(int j=0; j<edges.size(); j++){
Edge e = (Edge) edges.get(j);
e.display();
}
}
class Node1 {
int xpos, ypos;
int id;
Node1(int i){
id = i;
xpos = width/2;
ypos = height/5;
}
Node1(int x, int y, int i){
id = i;
xpos = x;
ypos = y;
}
void display(){
smooth();
fill(255);
if(id >= 100){
fill(0);
ellipse(xpos, ypos, 10, 10);
// text(""+id, xpos-10,ypos-10);
}else{
ellipse(xpos, ypos, 10, 10);
// text(""+id, xpos-10,ypos-10);
}
}
}
class Edge {
int idOr, idDest;
Edge(Node1 or, Node1 dest){
idOr = or.id;
idDest = dest.id;
}
void display(){
smooth();
Node1 orig = (Node1) nodes1.get(this.idOr);
Node1 dest = (Node1) nodes1.get(this.idDest); // Processing underline this line when the error is generated
strokeWeight(1);
stroke(255,0,0,100);
line(orig.xpos,
orig.ypos,
dest.xpos,
dest.ypos);
}
}