0

这是 LogCat 内容:

02-25 15:57:42.481: E/AndroidRuntime(1327): FATAL EXCEPTION: main
02-25 15:57:42.481: E/AndroidRuntime(1327): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hs.hospitalfinder/com.hs.hospitalfinder.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class MapView
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.os.Looper.loop(Looper.java:137)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.app.ActivityThread.main(ActivityThread.java:5039)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at java.lang.reflect.Method.invokeNative(Native Method)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at java.lang.reflect.Method.invoke(Method.java:511)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at dalvik.system.NativeStart.main(Native Method)
02-25 15:57:42.481: E/AndroidRuntime(1327): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class MapView
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.app.Activity.setContentView(Activity.java:1881)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at com.hs.hospitalfinder.MainActivity.onCreate(MainActivity.java:18)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.app.Activity.performCreate(Activity.java:5104)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-25 15:57:42.481: E/AndroidRuntime(1327):     ... 11 more
02-25 15:57:42.481: E/AndroidRuntime(1327): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.MapView" on path: /system/framework/com.google.android.maps.jar:/data/app/com.hs.hospitalfinder-1.apk
02-25 15:57:42.481: E/AndroidRuntime(1327):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.view.LayoutInflater.createView(LayoutInflater.java:552)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:643)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
02-25 15:57:42.481: E/AndroidRuntime(1327):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
02-25 15:57:42.481: E/AndroidRuntime(1327):     ... 22 more

嫌疑犯是:

m = (MapView)findViewById(R.id.mapView);

哪里m是:

private MapView m;

我不明白我哪里错了。请指导。

4

3 回答 3

1

在您的布局中,MapView 是否设置为com.google.android.maps.MapView

(另外,如果您还没有,请在https://developers.google.com/maps/documentation/android/上查看新的 Google Maps API,而不是您正在使用的 API V1)

于 2013-02-25T16:10:22.700 回答
0

检查您是否在应用程序清单中为地图声明了 uses-library 标记。

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >

    <uses-library android:name="com.google.android.maps" />
</application>
于 2013-02-25T16:42:49.163 回答
0

我认为您没有从MapActivity扩展。您应该从 MapActivity 而不是 Activity 扩展您的类。您可以从本教程中获得更多帮助:

http://mobiforge.com/developing/story/using-google-maps-android

于 2013-02-25T16:13:22.783 回答