将ArrayList添加到ArrayLists的ArrayList时遇到问题

Kal*_*lec 0 java eclipse debugging arraylist

public class Tabel {
    private static int dimension;

    private ArrayList<ArrayList<Character>> tabel;


    public Tabel(int dimension) {

        Tabel.dimension = dimension;

        for (int i=0;i<Tabel.dimension*Tabel.dimension;i++) {
           tabel.add(new ArrayList<Character>());
        }

     }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试调试(eclipse ide)时,我会遇到很多奇怪的"错误",或者至少我会遇到一些我认为意想不到的错误.

private static int不会出现在debug的"variables"部分.

我得到一个NullPointerExceptiontabel.add(...),但是当我观看了调试,它进入for一次,在表中不添加任何东西,因为当我点击"下一步",而不是跳转到花括号它跳出功能.

如果我发表评论,.add那就是问题(我认为).我的语法错了吗?或者我应该发布更多代码?

zw3*_*324 5

tabel 未初始化,因此它为null.

更改

private ArrayList<ArrayList<Character>> tabel;
Run Code Online (Sandbox Code Playgroud)

private ArrayList<ArrayList<Character>> tabel = new ArrayList<ArrayList<Character>>();
Run Code Online (Sandbox Code Playgroud)

或更好:

private List<ArrayList<Character>> tabel = new ArrayList<ArrayList<Character>>();
Run Code Online (Sandbox Code Playgroud)

因为这不扎tabelArrayList.