0

I have a problem with the java librairie OpenCSV. I didn't succeed to read all line of my CSV file, I read only the second line, I don't know why ...

My CSV file :

    "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","test@test.fr","14","11"
"0","Julie","Julie","Beginner","0878589632","1445856996","test3","93857","PAris","POKER","foo@foo.fr","14","11"

I use OpenCSV to create an android list, and only the line "Julie" "Julie" is added 3 times...

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();
        }
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Aureo91
  • 71
  • 7

2 Answers2

0

I take it map is some kind of dictionary? When you put values in the same keys over and over, it overwrites the previous value.

I recommend a different data structure based on the problem you are trying to solve.

beautifulcoder
  • 10,832
  • 3
  • 19
  • 29
0

Beautifulcoder hit the nail on the head. You are using the same key for every value you are inserting into the map so you are overwriting everything and will only see the last item you put in the map

Scott Conway
  • 975
  • 7
  • 13