膨胀 MapView 时出现问题

发布于 2024-11-14 15:05:32 字数 5404 浏览 3 评论 0原文

我正在浏览 Hello, MapView 处的文档来添加我的 Activity 的 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,我已将 use-library 标签添加到我的清单中,我正在具有 Google API 目标的模拟器中运行...

I'm going through the documentation at Hello, MapView to add a MapView to my Activity.

When I launch my Activity, I get an inflation error on the MapView.

Here is the MapView in my layout xml:

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

Here is the code in my MapActivity (the class is named ActivityDetails and extends MapActivity) class:

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

Here is the error:

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

As far as I can tell, I've done everything correct as described in the documentation. I've set my build target to Google APIs, I've added the uses-library tag to my Manifest, I'm running in an emulator with the Google API target...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

樱娆 2024-11-21 15:05:32

问题是我在 MapActivity 中的 setContentView() 之后调用 super.onCreate() 。

The problem was I was calling super.onCreate() after setContentView() in the MapActivity.

别挽留 2024-11-21 15:05:32

您为 MapView 使用了错误的 xml

扩展 MapActivity 的类应该使用包含此类内容的 xml 调用 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>

因此,不要使用layout_details.xml,而是使用layout.xml

You are using the wrong xml for your MapView

The class extending the MapActivity should call setContentView() with the xml containing stuff like this

<?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>

So instead of using layout_details.xml use layout.xml

酷遇一生 2024-11-21 15:05:32

将其插入 MapView 的 xml 声明中

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

Insert this on your xml declaration of the MapView

xmlns:android="http://schemas.android.com/apk/res/android"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文