android.view.InflateException:填充类片段时出错

时间:2016-10-05 01:36:14

标签: android android-fragments

我不知道我的问题是什么,但之前,这很好。所以我有这个Activity类MainMapActivity

public class MainMapActivity extends AppCompatActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_nav);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

activity_main_nav

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include xmlns:android="http://schemas.android.com/apk/res/android"
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <include
        layout="@layout/activity_main_map"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

以及随附的 activity_main_map

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:name="com.google.android.gms.maps.SupportMapFragment"/>

有人可以帮我解决问题吗?我非常需要一些答案。谢谢!

1 个答案:

答案 0 :(得分:1)

我曾经遇到过像这样的问题,我在XML中添加了一个名称属性。

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:name="com.testing.svma.MainActivity"/>

可能会解决问题。

另请查看以下内容:

  1. 检查清单中是否有必要的地图权限
  2. 确保元数据正确
  3. 希望这会有所帮助。

    P.S:问题也可能出在API级别或播放服务版本上。

相关问题