【发布时间】:2017-04-27 19:16:51
【问题描述】:
我正在尝试用 Java 编写一个程序来显示有多少
每个字符都包含在使用 BarChart 的 TextArea 内。
我编写了一个返回“XYChart.Series”的方法,其中包含
字符以及在TextArea中使用了多少次,
但是,每次通过按钮事件调用它时,它都会被挂钩
它只是根据
"java.lang.IndexOutOfBoundsException: Index: 100, Size: 0"
这是我写的方法
private XYChart.Series stringIntoSeries(String text)
{
char[] chars = text.toCharArray(); // char array of characters contained in string
List<List> usageList = new ArrayList(); // list to contain character usage
for(int i = 0; i < chars.length; i++)
{
char c = chars[i];
if(usageListHasChar(usageList, c)) // checks if character character has an entry in the list
{
int uI = usageListCharIndex(usageList, c); // finds index of the entry
List l = (List)usageList.get(uI);
l.set(1, (int)l.get(1)+1);
usageList.set(uI, l);
}
else // if not create new entry
{
List l = new ArrayList();
l.add(c);
l.add(1);
usageList.add(l);
}
}
XYChart.Series s = new XYChart.Series(); // new series to contain character usage
s.setName("");
for(int i = 0; i < usageList.size(); i++) // add characters and amount of times used
{
List l = usageList.get(i);
char character = (char)l.get(0);
int usage = (int)l.get(1);
s.getData().add(character, usage); // adds character and times used to series
}
return s; // returns the series once characters and usage are added which is then added to a BarChart
}
我得到的错误特别是在这一行
s.getData().add(character, usage); // adds character and times used to series
这里有什么问题?
【问题讨论】:
标签: java