嵌套的For循环会忽略Java中ArrayList中的GLine数组

时间:2018-06-24 10:42:57

标签: java arraylist

似乎Java忽略了嵌套在以下代码中的我的for循环之一:(Java仅添加ArrayList arrayListGLines的最后一个GLine数组-而不是同一ArrayList中的所有Array)。感谢任何可以提供帮助的人!

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

        }
    }

0 个答案:

没有答案