无法在xml文件中使用com.google.android.maps

时间:2012-04-29 17:29:00

标签: java android xml eclipse 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文件中,但app force在运行后关闭。

如果我不使用这部分,那么剩下的代码就可以执行了。

  1. 使用google API 2.3作为目标
  2. sdk version 1.6
  3. 使用Eclipse IDE for Java Developers 版本:Indigo Service Release 2 构建ID:20120216-1857
  4. 我放入了 清单文件中的应用程序标记。
  5. 我甚至使用过这些权限
  6. 但我可以编译它而没有任何错误但无法运行它。 我真的无法弄明白。 这是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**
    

2 个答案:

答案 0 :(得分:0)

尝试不使用“wrap_content”作为高度,因为它似乎抛出和通胀异常。尝试获取dp值。或者,如果要将其调整到布局中的某个特定位置,请使用相对布局并使其相对于其他视图元素进行拉伸。只是不要单独使用“wrap_content”。

如果这不起作用,请回复我,我会尝试进一步协助。

答案 1 :(得分:0)

应用程序标记下方的

添加<uses-library android:name="com.google.android.maps" /> xml指定android:layout_height="fill_parent"

如果可能,请尝试将项目构建目标Project->Properties->Android更改为Google API级别。