嵌套For循环忽略Java中ArrayList中的gline数组
Java似乎忽略了嵌套在以下代码中的一个for循环:(Java只添加ArrayList arrayListGLines中的最后一个GLines数组,而不是来自同一ArrayList的所有数组)。感谢所有能帮忙的人嵌套For循环忽略Java中ArrayList中的gline数组,java,arraylist,Java,Arraylist,Java似乎忽略了嵌套在以下代码中的一个for循环:(Java只添加ArrayList arrayListGLines中的最后一个GLines数组,而不是来自同一ArrayList的所有数组)。感谢所有能帮忙的人 GLine[] decadeLines = new GLine[NDECADES]; // instance var ArrayList<GLine[]> arrayListGLines = new ArrayList<GLine[]>(); // instan
GLine[] decadeLines = new GLine[NDECADES]; // instance var
ArrayList<GLine[]> arrayListGLines = new ArrayList<GLine[]>(); // instance var
...
private void graph() {
String entryString = database.findEntry(nameField.getText()).toString();
entryString = entryString.replace("[", "");
entryString = entryString.replace(",", "");
entryString = entryString.replace("]", "");
NameSurferEntry entry = new NameSurferEntry(entryString);
entry.getName();
for (int i = 0; i < NDECADES - 1; i++) {
decadeLines[i] = new GLine(i * (getWidth()/11), GRAPH_MARGIN_SIZE + entry.getRank(i) * (getHeight() - (2 * GRAPH_MARGIN_SIZE)) / MAX_RANK, (i + 1) * (getWidth()/11), GRAPH_MARGIN_SIZE + entry.getRank(i + 1) * (getHeight() - (2 * GRAPH_MARGIN_SIZE)) / MAX_RANK);
// sorry for the redundancy
//add(decadeLines[i]);
}
arrayListGLines.add(decadeLines);
for (int i = 0; i < arrayListGLines.size(); i++) {
for (int j = 0; j < arrayListGLines.get(i).length - 1; j++) {
System.out.println("arraylistsize " + arrayListGLines.size());
GLine[] arrayGLine = arrayListGLines.get(i);
add(arrayGLine[j]);
////add(arrayListGLines.get(i)[j]); alternative
if (i == 3) { // just trying to access the 3rd GLine[] of arrayListGLines
add(arrayListGLines.get(2)[3]); //- can't access this element's object which is a GLine
add(arrayListGLines.get(2)[4]);//- can't access this element's object which is a GLine
add(arrayListGLines.get(2)[5]);//- can't access this element's object which is a GLine
System.out.println("OK");} // been trying to debug that's why i have this
System.out.println(i + " " + j);// been trying to debug that's why i have this
}
}
GLine[]decadeline=新GLine[NDECADES];//实例变量
ArrayList arrayListGLines=新的ArrayList();//实例变量
...
私有void图(){
String entryString=database.findEntry(nameField.getText()).toString();
entryString=entryString.replace(“[”,”);
entryString=entryString.replace(“,”,”);
entryString=entryString.replace(“]”,“”);
NameSurferEntry条目=新的NameSurferEntry(entryString);
entry.getName();
对于(int i=0;i
add方法有什么问题?请向我们展示您的add()
-方法。问题可能就在那里。通常Java从不出错。总是程序员出错。;)我编辑了代码。谢谢。我没有遇到异常或错误,但我无法让Java做我想做的事情,即在画布中显示或添加数组中包含的所有行yList。只有最后一个第i个数组被添加到画布中。谢谢!@JR我们需要查看void add(GLine g){…}
方法,如上所述,问题可能来自此方法。