определение KmlLayer, но я получаю сообщение об ошибке Android Studio - PullRequest
0 голосов
/ 07 мая 2020

Я новичок в программировании, поэтому прошу прощения за некоторые глупости, которые могу сказать.

Итак, я хочу создать KmlLayer, который будет отображаться на моих картах Google. Я определил его (установил объект mMap, установил путь к файлу kml), но проблема в том, что он подчеркнут красным, а в разделе Build написано (я не могу запустить его из-за этой ошибки):

ошибка: незарегистрированное исключение XmlPullParserException; должен быть пойман или объявлен брошенным

Вот мой код:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    public GoogleMap mMap;
    private int i;
    private KmlLayer layer;

    @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);
        layer = new KmlLayer(mMap, R.raw.test,getApplicationContext());
        layer.addLayerToMap();
    }
    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

        // Add a marker in Sydney and move the camera
        LatLng slovenia = new LatLng(45, 15);
        mMap.addMarker(new MarkerOptions().position(slovenia).title("Slovenia"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(slovenia));

        final double[] latitude = new double[5];
        final double[] longitude =new double[5];
        i=0;

        //ko klikneš se naredi marker
        mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng point) {
                MarkerOptions marker =new MarkerOptions().position(new LatLng(point.latitude, point.longitude)).title("New Marker");
                mMap.addMarker(marker);
                //premakne te na nov marker
                mMap.moveCamera(CameraUpdateFactory.newLatLng(point));
                latitude[i]=point.latitude;
                longitude[i]=point.longitude;
                i++;
                //v spodnjem oknu ti izpiše koordinate
                for(int b=0; b<5;b++){
                    System.out.println(latitude[b]);
                }
            }
        });
    }
}

И скриншот:

Подчеркнуть KmlLayer

Что я здесь делаю не так?

...