下面的代码给出了问题,我只需要将字符串中的字母转换为字符,当我运行测试时,当代码到达时我不断收到错误char c = t.charAt(0);
确切的错误消息是:
java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:0
我无法将字符串字母变成字符。任何提示将非常感谢。
String[] zombies;
int num = 0;
Vector<Zombie> practice = new Vector<Zombie>();
String zombieString = "SZI1";
zombies = zombieString.split("");
for (String t : zombies) {
if (isNumeric(t)) {
int multiplier = Integer.parseInt(t);
String extraZombie = zombies[num - 1];
char x = extraZombie.charAt(0);
for (int i = 0; i <= multiplier; i++) {
Zombie zombie = Zombie.makeZombie(x);
practice.add(zombie);
}
} else {
char c = t.charAt(0);
//Zombie zombie = Zombie.makeZombie(c);
//practice.add(zombie);
num++;
}
}