使用HashMaps的ArrayList

Ada*_*dam -1 java arraylist hashmap

有人能告诉我下面的代码有什么问题吗?当我在try之后运行第一行下面的代码时{产生以下错误:

"java.lang.IndexOutOfBoundsException:Index:0,Size:0"

public static class ASIFFile {
            private ArrayList<HashMap<String,String>> data;
            private static int currRec = 0; //assign each record a numeric id based on this figure.

            // Method for reading ADIFfile  
            public ArrayList<HashMap<String,String>> ReadASIFfile (File DataFile) {      
                data = new ArrayList<HashMap<String, String>>(500);

                try {
                        HashMap<String, String> temp = new HashMap<String,String>(10);
                        data.set(currRec, temp);                        
                        (data.get(currRec)).put("recID", Integer.toString(currRec));//give the record a numeric ID


...  
Run Code Online (Sandbox Code Playgroud)

Kev*_*man 6

你永远不会添加任何东西ArrayList.您有一个ArrayList可以持有HashMaps,但目前empty.You有一个新的添加HashMap到您要使用该索引之前使用索引.