2015-12-12 63 views
0

我一直無法從一個csv文件中獲取數據到一個arrayList,所以我可以用它來製作多段線。無論我嘗試什麼,我都無法讓它正常工作。有沒有人有一個指向什麼即時通訊做錯了。 我正在使用Toast臨時查看結果。從csv到ArrayList

林期待的代碼給我一個ArrayList,但它只是返回我一個空列表

林補充說,在MainActivity

MapsActivity的文件中寫入地圖的活動,其中這應該發生和功能;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

private GoogleMap mMap; 

private GoogleApiClient client; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_maps); 
    // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 

    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
} 



@Override 
public void onMapReady(GoogleMap googleMap) { 

    mMap = googleMap; 
    FileInputStream fileInputStream = openFileInput("trip_file"); 
    InputStreamReader inputReader = new InputStreamReader(fileInputStream); 
    BufferedReader BufferedReader = new BufferedReader(inputReader); 
    List<LatLng> latLngList = new ArrayList<LatLng>(); 
    String line = ""; 

    try { 
     while((line = BufferedReader.readLine()) != null) // Read until end of file 
     { 
      double lat = Double.parseDouble(line.split(", ")[0]); 
      double lon = Double.parseDouble(line.split(", ")[1]); 
      latLngList.add(new LatLng(lat, lon)); 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

       String teest = String.valueOf(latLngList); 
       Toast.makeText(getBaseContext(), teest, 
         Toast.LENGTH_SHORT).show(); 
      } 

     } 

MainActivity中的這段代碼寫入文件;

public void onLocationChanged(Location location) { 

    double lat = location.getLatitude(); 
    double lon = location.getLongitude(); 

    myList.add(lat); 
    myList.add(lon); 

    String file_name = "trip_file"; 


    try { 
     String skrive = String.valueOf(myList); 
     FileOutputStream fileOutputStream = openFileOutput(file_name, MODE_PRIVATE); 
     fileOutputStream.write(skrive.getBytes()); 
     fileOutputStream.close(); 
     Toast.makeText(getApplicationContext(), "Location saved",Toast.LENGTH_LONG).show(); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

} 
+0

這是一個有點含糊。 SO在具體問題上做得更好。你期望什麼,取而代之的是什麼,避免給我們一堆亂碼,並要求我們「修復它」。 – arcy

回答