0

我正在创建一个 Google Map API v2 应用程序,但我在 LogCat 中发现了一个问题,并且 O 不知道如何解决它,谁能帮助我?

我正在使用 API Google 16。我已导入 Google Play 服务并添加到项目中,但我在 LogCat 中遇到了这个问题。

我将不胜感激。

主要的.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        android:name="com.google.android.gms.maps.SupportMapFragment"
        class="android.support.v4.app.DialogFragment"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

日志猫

 04-12 07:54:02.176: E/Trace(1119): error opening trace file: No such file or directory (2)
04-12 07:54:03.236: D/AndroidRuntime(1119): Shutting down VM
04-12 07:54:03.236: W/dalvikvm(1119): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
04-12 07:54:03.259: E/AndroidRuntime(1119): FATAL EXCEPTION: main
04-12 07:54:03.259: E/AndroidRuntime(1119): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemapv2/com.example.googlemapv2.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.os.Looper.loop(Looper.java:137)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.app.ActivityThread.main(ActivityThread.java:4745)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at java.lang.reflect.Method.invokeNative(Native Method)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at java.lang.reflect.Method.invoke(Method.java:511)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at dalvik.system.NativeStart.main(Native Method)
04-12 07:54:03.259: E/AndroidRuntime(1119): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.app.Activity.setContentView(Activity.java:1867)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at com.example.googlemapv2.MainActivity.onCreate(MainActivity.java:13)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.app.Activity.performCreate(Activity.java:5008)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-12 07:54:03.259: E/AndroidRuntime(1119):     ... 11 more
04-12 07:54:03.259: E/AndroidRuntime(1119): Caused by: java.lang.IllegalStateException: Fragment android.support.v4.app.DialogFragment did not create a view.
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:303)
04-12 07:54:03.259: E/AndroidRuntime(1119):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
04-12 07:54:03.259: E/AndroidRuntime(1119):     ... 21 more
4

1 回答 1

1

你的问题是这个错误行:

Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

基本上,如果您收到,那么您的问题可能是因为/是该库的一部分,因此fragment/class not found error缺乏对该库的良好参考:google-play-servicesMapFragmentSupportMapFragment

检查你的Android Dependencies文件夹是否(blue)google-play-services (orange)里面,你会发现有这个类的com.google.android.gms.maps包:(green)MapFragment(red)

在此处输入图像描述

如果不是这种情况,您可以查看我写的这篇博文的前 3 个步骤,以了解如何正确引用这个包:

谷歌地图 API V2

于 2013-04-12T07:16:21.963 回答