【问题标题】:Android: Cannot cast from View to MapViewAndroid:无法从 View 投射到 MapView
【发布时间】:2010-05-12 09:21:23
【问题描述】:

我正在尝试运行 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);

任何人都可以提供有关修复的建议吗?

干杯, 天然气。

【问题讨论】:

    标签: android casting android-mapview


    【解决方案1】:

    这可能源于您将自己的班级命名为MapView。尝试指定完整类 com.google.android.maps.MapView 以将其与您自己的 org.gaz.mapapp.MapView 区分开来。

    【讨论】:

    • 我不敢相信我忽略了这一点!谢谢弗兰克!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    • 2014-08-08
    相关资源
    最近更新 更多