Android: невозможно выполнить приведение из вида в MapView - PullRequest
1 голос
/ 12 мая 2010

Я пытаюсь запустить пример Android MapView, и в Eclipse появляется ошибка «Невозможно привести от View к MapView».

Мой макет выглядит следующим образом

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="0jwi0saLYCPGfO-t7glg5bQoBz7jVKWCcgyQWQA"
 />

<LinearLayout
    android:id="@+id/zoomview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/mapview"
    android:layout_centerHorizontal="true"
/>

</RelativeLayout>

и код активности

package org.gaz.mapapp;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ZoomControls;

import com.google.android.maps.*;

public class MapView extends MapActivity {

LinearLayout linearLayout;
MapView mapView;
ZoomControls mZoom;

public void onCreate(Bundle savedInstance) {
    linearLayout = (LinearLayout) findViewById(R.id.mainlayout);
    mapView = (MapView) findViewById(R.id.mapview);
    mZoom = (ZoomControls) mapView.getZoomControls();       
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
}

Ошибка вызвана строкой

mapView = (MapView) findViewById(R.id.mapview);

Кто-нибудь может предложить предложения по исправлению?

Cheers, Gaz.

1 Ответ

8 голосов
/ 12 мая 2010

Это, вероятно, связано с тем, что вы называете свой собственный класс MapView. Попробуйте указать полный класс com.google.android.maps.MapView, чтобы отличить его от вашего org.gaz.mapapp.MapView.

...