【问题标题】:arrayOutOfBounds exception java on my Java project我的Java项目上的arrayOutOfBounds异常java
【发布时间】:2014-01-07 23:05:44
【问题描述】:

我似乎找不到以下错误的问题:

线程“主”java.lang.ArrayIndexOutOfBoundsException 中的异常:31

在这部分代码中收到此错误:

for (int i = 0; i < templateKeuze.length(); i++) {
  if(woord[i].startsWith("?")){
    System.out.println("\nGeef je input voor de parameter "+woord[i]);
    vervang = Input.readLine();
    templateKeuze.replace(woord[i],vervang);
  } else{
    continue;
  }
}

【问题讨论】:

  • woord 的长度是多少?请注意,如果templateKeuzeString,则字符串是不可变的,因此您应该使用templateKeuze = templateKeuze.replace(woord[i],vervang);
  • 天哪,我只是智障,一直在寻找这个一个小时,猜是因为我累了。它必须是“word.length()”我的错。对不起。感谢您的回答,请随时将其发布为答案
  • templateKeuze.length()更改为woord.length()
  • 你可以删除这个问题。这不会为该网站增加更多价值。
  • @ZouZou 我认为他可以给出答案

标签: java indexoutofboundsexception


【解决方案1】:

您正在循环到templateKeuze 的长度,但在woord 上使用该索引。它们的长度一样吗?

【讨论】:

  • 不,它们的长度不一样,我一遍又一遍地忽略它,我的错,谢谢你的帮助!
猜你喜欢
  • 1970-01-01
  • 2014-07-27
  • 2013-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-10
  • 1970-01-01
相关资源
最近更新 更多