好的,所以我目前正在开发一个 Bukkit 插件,并决定添加一个安排广播的功能。为了存储广播,我使用了 config.yml 文件并从那里获取广播。我遇到的问题是代码不断返回并且我还无法修复的 IndexOutOfBoundsException。
这是我的代码:
package uk.co.thek4web.broadcaster;
import java.util.List;
import org.bukkit.scheduler.BukkitRunnable;
public class bcscheduler extends BukkitRunnable {
private Broadcaster plugin;
public bcscheduler(Broadcaster plugin){
this.plugin = plugin;
}
private int bcnumber = 0;
public void run() {
//String list from config
List<String> bcm = plugin.message();
//Broadcasts the next broadcast messsage in the config
plugin.bc(bcm.get(bcnumber));
//Makes sure broadcasts don't repeat, goes onto the next broadcast.
if(bcnumber < bcm.size()){
bcnumber++;
}
else{
bcnumber = 0;
}
}
}
这是我不断得到的例外:
2013-08-04 20:20:43 [WARNING] [Boss Broadcast] Task #4 for Boss Broadcast v0.3 generated an exception
java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
at java.util.ArrayList.rangeCheck(ArrayList.java:603)
at java.util.ArrayList.get(ArrayList.java:381)
at uk.co.thek4web.broadcaster.bcscheduler.run(bcscheduler.java:16)
at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftTask.run(CraftTask.java:53)
at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:522)
at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
我已经尝试了一些东西,但它们都没有奏效,所以任何关于我到底哪里出错的想法都将不胜感激。