我做了一些类来阅读Java中的KML文件(使用SAX)。我测试它,它工作正常。 然后我制作了我的jar,并将其导入到android项目中。 但是当我尝试阅读SAME kML时,我没有任何结果。解析器返回空列表(向量)
这就是我在Java中的表现:
Vector<Point> listPoints = new Vector<Point>();
String src = "C:/Users/A556520/Documents/Proyectos/PolygonDoubleKML/res/Glorias_def.kml";
InputStream inputStream =new FileInputStream(src);
ReaderKML kmlreader = new ReaderKML(inputStream);
time_start = System.currentTimeMillis();
listPoints = kmlreader.parseKML();
time_end = System.currentTimeMillis();
System.out.println("Tiempo de ejecución: "+ (time_end-time_start)/1000f);
输出正确 - &gt; Tiempodeejecución:0.073 || Npoints = 401
然后正如我所说,我将jar导入Android项目,这就是我的工作方式:
Vector<Point> lista;
Polygon glorias;
ReaderKML kmlReader;
String pathKML = "~res/raw/glorias_def.kml";
InputStream input_kml;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input_kml = getResources().openRawResource(R.raw.glorias_def);
kmlReader = new ReaderKML(input_kml);
lista = kmlReader.parseKML();
}
protected void onStart() {
super.onStart();
tv_1.setText("Npoints = "+Integer.toString(lista.size()));
}
我在textView中得到的是Npoints = 0
,当它必须是Npoints = 401
时......我不明白出了什么问题......
kml文件位于~res / raw中,与我以前在Java中测试的相同。