好的,所以我似乎无法得到这个工作,虽然很多人告诉我的语法和逻辑是正确的。任何人都可以向我透露我可能会做错什么?不能得到charAt(0)的工作
public Scanner in = new Scanner(System.in);
public void movePlayer() {
System.out.print("move: ");
String str = in.nextLine();
in.nextLine();
char c = str.charAt(0);
if (c == 'l' || c == 'L') {
player.moveLeft();
}
}
程序被烧焦处c = str.charAt(0);
抓而我正在被返回此错误:
java.lang.StringIndexOutOfBoundsException: 字符串索引超出范围:0(java.lang中.String)
Aaaaaand ...你尝试检查如果str不为空? – Raveline
这意味着str是空的(str ==“”),所以在0处没有字符。 – assylias
不是“not null”,空,对不起。为什么你有第二个in.nextLine()没有任何作用?这是故意的吗? – Raveline