android.view.InflateException: Binary XML file : Error inflating class fragment

前端 未结 6 1181
刺人心
刺人心 2020-12-22 07:19

I am using GoogleMap in android app using Android Studio. It was working fine and don\'t know why suddenly it stopped working. minSdkVersion is 15

相关标签:
6条回答
  • 2020-12-22 07:50

    After adding permission in manifest, It solved my issue. Check below code :

    <uses-permission
            android:name="android.permission.WRITE_EXTERNAL_STORAGE"
            android:maxSdkVersion="24" />
    <uses-permission
            android:name="android.permission.READ_EXTERNAL_STORAGE"
            android:maxSdkVersion="24" />
    
    0 讨论(0)
  • 2020-12-22 07:52

    getChildFragmentManager is used in Nested Fragments. The fragment you've used is not a child of another fragment. Use getSupportFragmentManager or getFragmentManager for fragment transactions.

    Take a look at this question for more information.

    In addition, I would like to mention that You're integrating an old Maps API. Try the latest one https://developers.google.com/maps/documentation/android-api/map

    0 讨论(0)
  • 2020-12-22 07:53

    If it crashes second time, you need to destroy it.

    public void onDestroy() {
        super.onDestroy();
        getFragmentManager().beginTransaction().remove(mapfragmentnamehere).commit();
    }
    
    0 讨论(0)
  • 2020-12-22 07:53
    public void onMapReady(GoogleMap googleMap) {
    
        setUpMap(googleMap);
    
    }
    
    0 讨论(0)
  • 2020-12-22 08:06

    Please use getMapAsync.

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this)
    
    0 讨论(0)
  • 2020-12-22 08:10

    In your onCreate add:

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

    In XML add context:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.___yourPackageName______"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <fragment
        android:id="@+id/mapFragment"
        class="com.google.android.gms.maps.SupportMapFragment"
        tools:context="com.___yourPackageName______"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    
    </FrameLayout>
    
    0 讨论(0)
提交回复
热议问题