0

我正在设计一个使用谷歌地图的应用程序。为了获取地图,我使用了以下代码:

    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. 使用 google APIs 2.3 作为目标
  2. sdk 版本 1.6
  3. 使用 Eclipse IDE for Java Developers 版本:Indigo Service Release 2 Build 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**
4

2 回答 2

0

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

如果这不起作用,请回复我,我会尽力提供进一步的帮助。

于 2012-04-29T18:24:14.320 回答
0

在应用程序标签下方添加<uses-library android:name="com.google.android.maps" />在 xml 中指定android:layout_height="fill_parent"

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

于 2012-05-08T12:52:43.043 回答