CSV missing values



我正在使用openCSV读取csv文件,以便为我的android应用程序扩展我的自动完成功能。尽管csv中的大多数值都被成功读取并膨胀为自动完成文本视图,但其中一些值是"丢失的"。例如,csv值"Los Angeles,CA",LAX不会被程序读取。

读取CSV:

  public void readCSV() throws IOException {
      InputStream is = this.getAssets().open("airport-codes.csv");
      InputStreamReader ifr = new InputStreamReader(is, "UTF-8");
      CSVReader reader = new CSVReader (ifr);
      ArrayList<String> srd = new ArrayList<>();
      while ((reader.readNext()) != null)
      {
          nextLine = reader.readNext();
          Log.i("ArrivalTest", nextLine[0] + "- " + nextLine[1]);
          srd.add(nextLine[0] + " - " + nextLine[1]);
      }
      reader.close();
      autoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.originCityAutoComp1);
      adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, srd);
      autoCompleteTextView.setAdapter(adapter);
 }

airport-codes.csv:

...
"Lorient, France ",LRT
"Los Angeles, CA ",LAX    // Los Angles LAX is in csv file.
"Los Cabos, Mexico ",SJD
...

Logcat:

...
Longview, TX - GGG
Lonorore, Vanuatu - LNE
Lord Howe Island, NS, Australia - LDH
Lorient, France - LRT
Los Cabos, Mexico - SJD      // Los Angles LAX is missing.
Losuia, Papua New Guinea - LSA
Lourdes/Tarbes, France - LDE
...

while循环会从CSV文件中擦除每一行奇数数据并将其丢弃:)

试试这个:

while ((nextLine = reader.readNext()) != null) 
{
   Log.i("ArrivalTest", nextLine[0] + "- " + nextLine[1]);
   srd.add(nextLine[0] + " - " + nextLine[1]);
}

相关内容

  • 没有找到相关文章

最新更新