2012-02-22 116 views
0

我正在android工作。我想在我的活动中显示简单的Google地图。Android Google地图不显示

这是我的main.xml

<?xml version="1.0" encoding="utf-8"?> 
<com.google.android.maps.MapView 
xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/mapview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:clickable="true" 
android:apiKey="mykey" 
/> 

这是我的活动: -

package com.quepplin; 

import android.app.Activity; 

import android.os.Bundle; 

import com.google.android.maps.MapView; 

public class GooglemapActivity extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
MapView mMapView; 
mMapView = (MapView) findViewById(R.id.mapview); 
mMapView.setBuiltInZoomControls(true); 

} 

}

我已经创建了谷歌成功的关键。但是,每当我运行我的应用程序,然后它崩溃。并在logcat中显示以下错误: -

java.lang.RuntimeException: Unable to start activity 
android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.maps.MapView 

Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.maps.MapView 

    at android.view.LayoutInflater.createView(LayoutInflater.java:513) 

请帮我解释我做了什么错误。我很新创建谷歌地图。我在等待建议。

预先感谢您。

回答

3

如果我没看错,然后

public class GooglemapActivity extends Activity 

应该

public class GooglemapActivity extends MapActivity 

,并在您的清单文件..

<uses-library android:name="com.google.android.maps" /> 

而且你application build platform is Google-api

1

公共类GooglemapActivity扩展MapActivity {

+0

http://developer.android.com/resources/tutorials/views/hello-mapview.html – 2012-02-22 11:44:00

+0

user370305,凯文庇护, KK_07k11A0585谢谢先生,非常感谢你...爱你们所有人... – 2012-02-22 11:47:26

+0

WELCOME .................... – 2012-02-22 11:56:55

6

使用MapActivity而不是为活动

public class GooglemapActivity extends MapActivity {