0

我只是按照非常简单的说明创建一个新的 Android 应用程序以将地图(使用此处的说明:https ://developers.google.com/maps/documentation/android/start )加载到主屏幕中。我有以下错误:

02-11 19:36:02.078: WARN/dalvikvm(2740): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
02-11 19:36:02.118: ERROR/AndroidRuntime(2740): FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.mapexample/com.example.android.mapexample.MyActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
        at android.app.ActivityThread.access$1500(ActivityThread.java:132)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:150)
        at android.app.ActivityThread.main(ActivityThread.java:4263)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:231)
        at android.app.Activity.setContentView(Activity.java:1742)
        at com.example.android.mapexample.MyActivity.onCreate(MyActivity.java:18)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
        ... 11 more
        Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.android.mapexample-1.apk]
        at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at android.view.LayoutInflater.createView(LayoutInflater.java:471)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
        ... 19 more
02-11 19:36:02.158: WARN/ActivityManager(121): Force finishing activity com.example.android.mapexample/.MyActivity
02-11 19:36:02.668: WARN/ActivityManager(121): Activity pause timeout for HistoryRecord{40547a60 com.example.android.mapexample/.MyActivity}

我正在使用 IntelliJ IDEA 12,并且尝试将 google-play-services.jar 添加到模块中。

4

1 回答 1

1

如果您的目标 API 级别 < 12,则需要为此添加支持库,因此显示地图的活动将扩展android.support.v4.app.FragmentActivity类。并且在您的布局地图片段类中必须是com.google.android.gms.maps.SupportMapFragment。例如

<fragment
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />
于 2013-02-11T13:05:35.647 回答