2014-06-13 70 views
0

我有一個JAVA librairie OpenCSV的問題。我沒有成功讀我的CSV文件的所有行,我只讀第二行,我不知道爲什麼......OpenCSV - 全部讀取

我的CSV文件:

"NumACLEB","Nom","Prenom","Niveau","Telephone","Portable","Rue","Code Postale","Ville","Activite","Adresse Mail","Cotisation Acleb","Cotisation Adherent" 
"0","Pierre","Paul","Jacques","0585987445","0187458596","tests","92569","PARIS","POKER","[email protected]","14","11" 
"0","Julie","Julie","Beginner","0878589632","1445856996","test3","93857","PAris","POKER","[email protected]","14","11" 

我用OpenCSV來創建Android列表,只有行「朱莉」,「朱莉」加入3倍...

try 
     { 
      CSVReader csvReader = new CSVReader(new FileReader(SettingsActivity.SaveFolder+"PDF/Liste_Membres.csv"),'\t'); 
      //List<String[]> content = csvReader.readAll(); 
      String[] row = csvReader.readNext(); 
      while(row != null) 
      { 
       if(row[1]!="Nom") 
       { 
        map.put("viewname", row[1]+" "+row[2]); 
        map.put("viewDetails", "Ville : "+row[8]+" Cotisation ACLEB : "+row[11]+"€ Cotisation poker : "+row[12]+"€"); 
        map.put("img", String.valueOf(R.drawable.aclebapc_logo)); 
        listItem.add(map); 
       }else 
       { 
        map.put("viewname", "NOM Prenom"); 
        map.put("viewDetails", "Ville - Cotisation ACLEB - Cotisation poker"); 
        map.put("img", String.valueOf(R.drawable.aclebapc_logo)); 
        listItem.add(map); 
       } 
       row = csvReader.readNext(); 
      } 
     }catch(IOException ex) 
     { 
      Context context = getApplicationContext(); 
      CharSequence text = "Erreur lors de l'ouverture du fichier CSV..."; 
      int duration = Toast.LENGTH_SHORT; 
      Toast toast = Toast.makeText(context, text, duration); 
      toast.show(); 
     } 

回答

0

我把它map是某種詞典?當您將值反覆放入相同的鍵時,它會覆蓋以前的值。

根據您嘗試解決的問題,我推薦使用不同的數據結構。

0

Beautifulcoder撞在頭上。對於要插入到地圖中的每個值,您都使用相同的密鑰,因此您將覆蓋所有內容,並且只會看到您放入地圖的最後一個項目