【问题标题】:Unable to extend the MapActivity class?无法扩展 MapActivity 类?
【发布时间】:2013-02-16 22:12:12
【问题描述】:

我正在我的应用上实施 Google 地图。

我已经获取了我的 API 密钥等,目前正在学习一系列教程。我需要扩展 MapActivity 超类,但目前无法这样做。

我已经在我的清单中实现了地图库,并在我的 XML 布局中插入了 API 密钥。

但仍然收到“MapActivity 无法解析为类型”错误。 这是我的清单:

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

<uses-sdk android:minSdkVersion="8" />

<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".MainMap"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  <uses-library android:name="com.google.android.maps" />
</application>
</manifest>

这是我的 XML:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
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:enabled="true"
    android:clickable="true"
    android:apiKey="AIzaSyCJSfjl_7lU7-HKV3yIf5nnMODl6qiG2_g"
    />

 </RelativeLayout>

还有我的班级:

package com.example.map;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainMap extends MapActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maplayout);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.maplayout, menu);
    return true;
}

}

【问题讨论】:

    标签: java android api google-maps


    【解决方案1】:

    确保您的构建目标(例如,Eclipse 中的项目 > 属性 > Android)适用于 Android SDK 的“Google API”版本。

    【讨论】:

    • 这么简单,非常感谢 commonWare。当我有能力时,会将您的答案标记为正确
    【解决方案2】:

    试试这个:

    您选择项目构建目标是使用您的项目属性的 Google API

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 2013-08-14
      • 2014-06-19
      • 2011-04-06
      • 1970-01-01
      相关资源
      最近更新 更多