2016-05-03 23 views
-1

List<List<Integer>>のアウト・オブ・バウンズ例外を適切に初期化する際に問題があります。 0番目の位置にant要素が含まれていないため、内側のリストに要素が見つからないことがわかります。だから私の質問は、適切にArraylistの初期化

public static void main(String[] args) throws FileNotFoundException, IOException { 
    // HashMap to stock all my items with keys that i will use for minhashing 
    HashMap<String,Integer> hmap= new HashMap<>(); 
    //Matrice de signatures 
    List<List<Integer>> MinHash = new ArrayList<>(); 

    int numberHashing=6; 
    int i=0; 
    int nbItems; 

    List <Integer> a = new ArrayList<>(); 
    List <Integer> b = new ArrayList<>(); 
    //to read my sets that i defined that are the keys 
    FileReader in=new FileReader("C:\\items\\items.txt"); 
    BufferedReader brr = new BufferedReader(in); 
    String set ; 

    while((set = brr.readLine()) != null) 
     { 
      StringTokenizer t = new StringTokenizer (set); 
      for(int j=0;j<numberHashing;j++) 
      { 

       MinHash.get(j).add(10000); 
      } 
      while(t.hasMoreTokens()) 
      { 
       String item=(t.nextToken()); 
       if(!hmap.containsKey(item)) 
       { 
        hmap.put(item,i); 
        i++; 
       } 
      } 
      System.out.println(); 
     } 
    System.out.println(MinHash); 
} 

値を加えながらnumberHashingは後でそれらを格納することを心配する必要性と、リストaとbは、私の鍵をシャッフルしません別のクラスに使用されます私の内側のリストを反復処理する方法です。私のMinHashは10000で初期化したいarrayListです。私は反復のために使用しているファイルには、それぞれの行に4行と5語が含まれています。すでに答えられている簡単な質問かもしれませんが、助けていただきありがとうございます。

答えて

0

あなたのwhile前にこの初期化を追加し、MinHashためnumberHashing要素を作成しないでください:

for(int j = 0; j < numberHashing; ++j) 
{ 
    MinHash.add(new ArrayList<Integer>()); 
}