2012-04-29 36 views
0

我正在設計一個使用Google地圖的應用程序。爲了得到地圖,我使用了以下代碼:無法在xml文件中使用com.google.android.maps

com.google.android.maps.MapView 
    android:id="@+id/mapview" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:clickable="true" 
    android:apiKey="0V1xMgGND8LqWx0wO3Vkgs8Rj27aVCRp0biowfw" /> 

在xml文件中,但運行它後應用程序強制關閉。

如果我不使用這部分,那麼其餘的代碼執行一切正常。

  1. 使用谷歌的API 2.3作爲目標
  2. SDK版本使用Eclipse IDE爲Java開發者 1.6版
  3. :靛藍服務發佈2 版本ID:20120216-1857
  4. 我有 內建成應用程序標籤在清單文件中。
  5. 我甚至使用權限

不過,我可以編譯它沒有任何錯誤,但無法運行。 我真的搞不清楚。 這是由logcat生成的日誌。 我可以從任何人得到一些幫助...?

04-29 22:14:32.553: D/dalvikvm(415): GC_CONCURRENT freed 261K, 48% free 
    2963K/5639K, external 411K/517K, paused 5ms+5ms 
    04-29 22:14:32.863: D/dalvikvm(415): GC_CONCURRENT freed 447K, 49% free 
    3086K/5959K, external 411K/517K, paused 5ms+7ms 
    04-29 22:14:33.133: D/dalvikvm(415): GC_CONCURRENT freed 326K, 46% free 
    3271K/6023K, external 411K/517K, paused 5ms+6ms 
    04-29 22:14:33.203: D/AndroidRuntime(415): Shutting down VM 
    04-29 22:14:33.203: W/dalvikvm(415): threadid=1: thread exiting with uncaught 
    exception (group=0x40015560) 
    04-29 22:14:33.303: E/AndroidRuntime(415): FATAL EXCEPTION: main 
    04-29 22:14:33.303: E/AndroidRuntime(415): java.lang.RuntimeException: Unable to 
    start activity ComponentInfo{com.my.map/com.my.map.MapActivity}: 
    android.view.InflateException: Binary XML file line #6: Error inflating class 
    com.google.android.maps.MapView 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.os.Looper.loop(Looper.java:130) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.app.ActivityThread.main(ActivityThread.java:3683) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at java.lang.reflect.Method.invoke(Method.java:507) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run 
    (ZygoteInit.java:839) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at dalvik.system.NativeStart.main(Native Method) 
    04-29 22:14:33.303: E/AndroidRuntime(415): Caused by: android.view.InflateException: 
     Binary XML file line #6: Error inflating class com.google.android.maps.MapView 
    04-29 22:14:33.303: E/AndroidRuntime(415):  
     at android.view.LayoutInflater.createView(LayoutInflater.java:518) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at com.android.internal.policy.impl.PhoneWindow.setContentView 
     (PhoneWindow.java:207) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.app.Activity.setContentView(Activity.java:1657) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at com.my.map.MapActivity.onCreate(MapActivity.java:17) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
    04-29 22:14:33.303: E/AndroidRuntime(415):  
     ... 11 more 
    04-29 22:14:33.303: E/AndroidRuntime(415): Caused by: 
     java.lang.reflect.InvocationTargetException 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at java.lang.reflect.Constructor.constructNative(Native Method) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:415) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at android.view.LayoutInflater.createView(LayoutInflater.java:505) 
    04-29 22:14:33.303: E/AndroidRuntime(415): ... 21 more 
    04-29 22:14:33.303: E/AndroidRuntime(415): Caused by: 
     java.lang.IllegalArgumentException: MapViews can only be created insideinstances 
     ofMapActivity. 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at com.google.android.maps.MapView.<init>(MapView.java:291) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at com.google.android.maps.MapView.<init>(MapView.java:264) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    at com.google.android.maps.MapView.<init>(MapView.java:247) 
    04-29 22:14:33.303: E/AndroidRuntime(415): 
    ... 24 more 
04-29 22:14:45.193: I/Process(415): Sending signal. PID: 415 SIG: 9** 
+0

嘗試包括項目中的地圖庫..你可以從你的android-sdk獲得 - > addons – sampath

回答

0

嘗試,因爲它似乎拋出和通貨膨脹異常不使用高度「WRAP_CONTENT」。嘗試去找一個dp值。或者,如果您希望將其調整到佈局中的某個特定位置,請使用相對佈局,並使其相對於其他視圖元素拉伸。不要單獨使用「wrap_content」。

如果這沒有奏效,請回到我身邊,我會盡力協助您。

+0

你好,OneManMobile,我改變了使用「wrap content」的地方。我已經在dp中指定了自己的值。我可以看到圖形佈局,但應用仍然強制關閉。 。我按照這個教程joshclemm.com/blog/?p=148 –

0

應用標籤下方添加<uses-library android:name="com.google.android.maps" />內 的XML指定android:layout_height="fill_parent"

如果可能嘗試改變項目的構建目標Project->Properties->Android到谷歌API的級別。

相關問題