2012-02-22 147 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 {