FileInputStream KmlLayer不正确

时间:2018-05-31 17:20:02

标签: android kml

在我的班级 MapsActivity.java 中,除了onCreate之外,我创建了

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    try {
        layer = new KmlLayer(mMap, generateNoteOnStorage(getApplicationContext(), "kmll.kml", contenuto), getApplicationContext());
        //layer = new KmlLayer(mMap, R.raw.kmll, getApplicationContext());

    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        layer.addLayerToMap();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    }

}

public FileInputStream generateNoteOnStorage(Context context, String sFileName, String sBody) {
        try {
            File root = new File(Environment.getRootDirectory(), "kmlfiles");
            if (!root.exists()) {
                root.mkdirs();
            }
            File gpxfile = new File(root, sFileName);
            FileWriter writer = new FileWriter(gpxfile);
            writer.append(sBody);
            writer.flush();
            writer.close();
            Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show();
            return new FileInputStream(gpxfile);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

我无法理解为什么这段代码错了。我很确定它是由于FileInputStream程序(也是因为我对它们不那么友好)。 这是错误: screen

我还尝试将kmll.kml(生成的文件)复制到res / raw然后,而不是generateNoteOnStorage(getApplicationContext(), "kmll.kml", contenuto)我用R.raw.kmll替换它并且它有效。

0 个答案:

没有答案