0

我的原始文件夹中有一个带有此文本的 txt:

38.706937,-0.494406,Alcoy,Alcoy,Comunidad Valenciana
37.605651,-0.991294,Vuelo1,Cartagena,Región de Murcia
37.652022,-0.719147,Vuelo2,La Manga del Mar Menor,Región de Murcia
42.817988,-1.644183,Vuelo3,Pamplona,Navarra
36.750779,-5.812395,Vuelo4,Arcos de la frontera,Andalucia

我这样做的方法是:

private void leerPuntosApp(){
    InputStream stream =getResources().openRawResource(R.raw.sitios);
    BufferedReader brin = new BufferedReader(new InputStreamReader(stream));
    String todoPartes = null;

    try {
        while(brin.read() != -1){
            todoPartes = brin.readLine();
            dibujarPuntos(todoPartes);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

private void dibujarPuntos(String punto){
    Toast.makeText(this, punto, Toast.LENGTH_SHORT).show();
    String []separados = punto.split(",");

        Dialog dialog = hacerDialogo(separados[0],separados[1],
                  separados[2],separados[3],separados[4]);

        itemOverlay = new CargarItem(puntosMapa,this,dialog);

        lat = Double.parseDouble(separados[0])*1E6;
        lon = Double.parseDouble(separados[1])*1E6;

        GeoPoint point = new GeoPoint(lat.intValue(),lon.intValue());
        //GeoPoint point = calcularCoordenadas(listaDeSitios.get(i).getCiudad());

        item = new OverlayItem(point,separados[2], null);
        itemOverlay.addOverlay(item);
        mapOverlays.add(itemOverlay);
        mapView.postInvalidate();

}

奇怪的是,方法 dibujarPuntos 只画了第一点,但 toast 向我展示了所有的线条。

谢谢您的帮助。

4

2 回答 2

0

By doing the read() you are eating the first character of the line... are you sure the Toast was showing the correct data?

See if this helps

try {
    while((todoPartes = brin.readLine()) != null){
        dibujarPuntos(todoPartes);
    }
} catch (IOException e) {
    e.printStackTrace();
}

And instead of using Toast for logging, just use Log.d("MYTAG", punto) and then check the LogCat output to see if it's parsing the information correctly.

于 2012-06-11T18:26:00.810 回答
0

确实 read() 吃掉了除第一行之外的所有行的第一个字符。但是如果我这样做,你说我在这一行有一个 NumberFormatException

lat = Double.parseDouble(separados[0])*1E6;
于 2012-06-11T18:40:50.263 回答