1

我创建了一个新MapActivityMapProba

Activity我想显示的主要MapActivity内容:在按钮单击事件中,我输入了以下代码:

    Intent myIntent = new Intent(this, com.art.mode.MapProba.class);        
    startActivity(myIntent); 

但我收到强制关闭错误。

在我的 xml 文件中,我使用以下代码:

<LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">

      <com.google.android.maps.MapView
        android:id="@+id/map_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="SomeGoogleMapAPIKeyHere" />
</LinearLayout>

在日志中我收到此错误:

08-31 04:47:10.218: ERROR/AndroidRuntime(593): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.art.mode/com.art.mode.MapProba}: 
android.view.InflateException: Binary XML file line #7: Error inflating class com.google.android.maps.MapView

第 7 行是:com.google.android.maps.MapView

当我删除此代码表单 xml 文件时:

   <com.google.android.maps.MapView
    android:id="@+id/map_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:apiKey="SomeGoogleMapAPIKeyHere" />

出现空白黑屏(没有错误)

在清单文件中,我有:

uses-permission android:name="android.permission.INTERNET"
uses-permission android:name="android.permission.ACCESS_LOCATION" 

<uses-library android:name="com.google.android.maps" />

任何的想法?

谢谢


更新

08-31 12:22:00.648: ERROR/AndroidRuntime(656): FATAL EXCEPTION: main
08-31 12:22:00.648: ERROR/AndroidRuntime(656): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.art.mode/com.art.mode.MapProba}: android.view.InflateException: Binary XML file line #7: Error inflating class com.google.android.maps.MapView
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.os.Looper.loop(Looper.java:123)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at java.lang.reflect.Method.invokeNative(Native Method)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at java.lang.reflect.Method.invoke(Method.java:521)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at dalvik.system.NativeStart.main(Native Method)
08-31 12:22:00.648: ERROR/AndroidRuntime(656): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.google.android.maps.MapView
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.app.Activity.setContentView(Activity.java:1647)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at com.art.mode.MapProba.onCreate(MapProba.java:12)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     ... 11 more
08-31 12:22:00.648: ERROR/AndroidRuntime(656): Caused by: java.lang.reflect.InvocationTargetException
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at com.google.android.maps.MapView.<init>(MapView.java:238)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at java.lang.reflect.Constructor.constructNative(Native Method)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     ... 21 more
08-31 12:22:00.648: ERROR/AndroidRuntime(656): Caused by: java.lang.NullPointerException
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:382)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at com.google.android.maps.MapView.<init>(MapView.java:280)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     at com.google.android.maps.MapView.<init>(MapView.java:255)
08-31 12:22:00.648: ERROR/AndroidRuntime(656):     ... 25 more
4

4 回答 4

3

我有同样的问题,你必须把这个标签放在你的 AndroidManifest.xml

<uses-library android:name="com.google.android.maps"/>

它应该在里面:

<application>
    <uses-library android:name="com.google.android.maps"/>
</application>

!!!!从不,从不在外面

并将其用于您的活动

Intent myIntent = new Intent(getBaseContext(), MapProba.class);             
startActivity(myIntent);  
于 2011-02-10T12:32:33.713 回答
0

你能发送更多的错误日志吗,紧随其后的是什么

XML 文件第 7 行:膨胀类 com.google.android.maps.MapView 时出错 ...

它可能会告诉为什么它不能膨胀这个类,它是否不存在,或者它缺少库......等等......

-- 更新后 --

你在什么样的设备上运行这个?

如果您使用模拟器,则需要使用 Google API 作为构建目标。

如果您使用的是真实设备,它应该可以在 G1 上正常工作,但如果它是您从 AOSP 移植 Android 的设备,您很可能没有安装正确的库。

具体来说,您应该有 com.google.android.maps.jar 和 com.google.android.maps.xml 之类的文件。那里有一个很好的教程来使用 mapview:http: //developer.android.com/resources/tutorials /views/hello-mapview.html

于 2010-08-31T03:12:26.417 回答
0

在您的 Maps 表单类中,您是否使用extends MapActivityextends Activity? 在我意识到我使用了错误的扩展类之前,这让我感到很困惑。:P

于 2011-02-01T21:27:53.080 回答
0

如果您使用外部设备进行调试,很可能它没有安装正确的库。

特别是对于 archos 用户,请查看http://code.google.com/p/archos-apps-installer/downloads/detail?name=gAppsInstaller_v5-final.apk

于 2011-10-12T11:54:25.510 回答