问题描述
我有4个复选框,当被选择时,他们应该串联到单个串上的JLabel显示.它在排序之前一直在工作,不确定我是怎么做的,现在我得到了数组异常超出范围的错误.每当复选框与之交互时,这就是运行的update()方法.
I have 4 checkboxes, when selected they should concatenate onto a single string displayed on a Jlabel. It was working before sort-of, not sure whatI did to break it, now I get array exception out of bounds errors. This is the update() method being run whenever a checkbox is interacted with.
谢谢大家的回答,只是弄乱了我的初始数组声明.
It's been answered thanks all, just messed up my initial array declaration.
推荐答案
您似乎正在迭代到不存在的索引:
It looks like you're iterating to an index that does not exist:
for (int j = 0; j <= oslist2.length; j++)
应该是
for (int j = 0; j < oslist2.length; j++)
Java数组索引为(0,1,2 ... length-1)
Java array indexes are (0, 1, 2... length-1)
您也有
oslist2[3]="";
这意味着您应该使数组更大,或者不要使用该索引.这应该起作用:
which means, you should make the array bigger, or don't use that index.This should work:
String[] oslist2 = new String[4];
这篇关于简单复选框程序上的数组超出范围异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!