2011-06-10 348 views
3

我正在閱讀文檔Hello, MapView以將MapView添加到我的活動中。膨脹問題MapView

當我啓動我的Activity時,MapView上出現通貨膨脹錯誤。

這裏是我的佈局XML的MapView:

<com.google.android.maps.MapView 
    android:id="@+id/mymap" 
    android:layout_width="fill_parent" 
    android:layout_height="200dip" 
    android:clickable="true" 
    android:apiKey="withheld" 
    /> 

這裏是我的MapActivity代碼(類名爲ActivityDetails並延伸MapActivity)類:

MapView mMap; 
    mMap = (MapView) findViewById(R.id.mymap); 
    mMap.setBuiltInZoomControls(true); 

以下是錯誤:

06-10 09:15:24.277: ERROR/AndroidRuntime(228): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app/com.my.app.activity.ActivityDetails}: android.view.InflateException: Binary XML file line #35: Error inflating class com.google.android.maps.MapView 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.app.ActivityThread.access$2200(ActivityThread.java:119) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.os.Handler.dispatchMessage(Handler.java:99) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.os.Looper.loop(Looper.java:123) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.app.ActivityThread.main(ActivityThread.java:4363) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at java.lang.reflect.Method.invokeNative(Native Method) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at java.lang.reflect.Method.invoke(Method.java:521) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at dalvik.system.NativeStart.main(Native Method) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228): Caused by: android.view.InflateException: Binary XML file line #35: Error inflating class com.google.android.maps.MapView 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.view.LayoutInflater.createView(LayoutInflater.java:513) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:621) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:621) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.app.Activity.setContentView(Activity.java:1622) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at com.my.app.activity.ActivityDetails.onCreate(ActivityDetails.java:128) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  ... 11 more 
06-10 09:15:24.277: ERROR/AndroidRuntime(228): Caused by: java.lang.reflect.InvocationTargetException 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at com.google.android.maps.MapView.<init>(MapView.java:237) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at java.lang.reflect.Constructor.constructNative(Native Method) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at android.view.LayoutInflater.createView(LayoutInflater.java:500) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  ... 23 more 
06-10 09:15:24.277: ERROR/AndroidRuntime(228): Caused by: java.lang.NullPointerException 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:183) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at com.google.android.maps.MapView.<init>(MapView.java:279) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  at com.google.android.maps.MapView.<init>(MapView.java:254) 
06-10 09:15:24.277: ERROR/AndroidRuntime(228):  ... 27 more 

據我所知道的,我所做的一切正確的,因爲在描述文檔。我已經將我的構建目標設置爲Google API,我已將uses-library標記添加到我的Manifest,我正在模擬器中運行Google API目標...

+0

MapActivity.Java你的XML聲明是谷歌的API庫 – Andrew 2011-06-10 14:32:20

+0

只是刪除我的愚蠢了互聯網:-P的一部分。這也試着:-) – 2011-06-10 14:40:37

回答

6

問題是我是班上在setContentView()之後調用super.onCreate() )在MapActivity中。

+0

有時候google會使我desapoints :( – 2013-02-28 17:12:30

0

您正在使用錯誤的xml你的MapView

延長MapActivity應該調用的setContentView()與含有這樣的東西

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <com.google.android.maps.MapView 
    android:id="@+id/racemap" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_x="0px" 
    android:enabled="true" 
    android:clickable="true" 
    android:apiKey="blahblahblah" /> 
</LinearLayout> 

的XML所以不是使用layout_details.xml使用layout.xml

+1

這是我有什麼:公共類ActivityDetails擴展MapActivity – Andrew 2011-06-10 14:29:14

+0

噢什麼ActivityDetails.java:128? – Reno 2011-06-10 14:32:09

+0

setContentView(R.layout.layout_details); – Andrew 2011-06-10 14:33:10

0

插入此上的MapView

xmlns:android="http://schemas.android.com/apk/res/android"