public void ZeichneFigur(String position) {
String[] parts = position.split("\\.");
String part0 = parts[0];
String part1 = parts[1];
int k = Integer.valueOf(part1);
if (part0.equals("gr"))
g.setColor(Color.GREEN); }
switch (k) {
case 1:
g.fillOval(20,20,100,100);
Break;
case 2:
g.fillOval(20,30,100,100);
Break;
case 3:
g.fillOval(20,40,100,100);
Break;
case 4:
g.fillOval(20,50,100,100);
Break;
case 5:
g.fillOval(20,60,100,100); Break;}
First of all let me excuse my barbaric coding im a beginner. Im trying to write a short Method that takes strings of the format gr.2 that define values of the players color and the field that he is on, then paints ovals on the corresponding position. (Actually i have 40 cases, they are all the same). When i compile i get the ArrayINdexOutOfBoundsException, and i cant find out why, i understand that this means my index is out of range, but how does that happen when i enter gr.1 ?
EDIT: Changed if (part0.equals("gr")) and added break statements.