0

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 and targetSdkVersion is 24. Please check my below code and help me to come out of this :

XML:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/mapFragment"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

Gridle:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.google.maps.android:android-maps-utils:0.4.3'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.google.code.gson:gson:2.7'
    compile 'com.googlecode.android-query:android-query:0.24.3'
    compile 'com.makeramen:roundedimageview:2.2.1'
}

Java:

    public class MapsActivity extends Fragment implements OnMapReadyCallback,
            GoogleApiClient.ConnectionCallbacks,
            GoogleApiClient.OnConnectionFailedListener,
            LocationListener {
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
          SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
                        .findFragmentById(R.id.mapFragment);
          }
    }

Manifest:

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="@string/google_maps_key" />

Error:

It is giving error in xml at <fragment, error: android.view.InflateException: Binary XML file : Error inflating class fragment

17
  • Is your Activity extends FragmentAcitvity or a Normal Activity? Commented Sep 23, 2016 at 12:26
  • @MD, It extends v4 Fragment. Commented Sep 23, 2016 at 12:27
  • What error is throwing ? Commented Sep 23, 2016 at 12:40
  • @Piyush, It is giving error in xml at <fragment, error: android.view.InflateException: Binary XML file : Error inflating class fragment Commented Sep 23, 2016 at 12:41
  • Change it to MapFragment. Commented Sep 23, 2016 at 12:43

6 Answers 6

4

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" />
Sign up to request clarification or add additional context in comments.

6 Comments

It's working, but why? I think android:maxSdkVersion="22" is most appropriate. By the way, It seems slower than before, like it gets stuck for some ms.
@Grender, I removed maxSdkVersion and it is working fine. No need of it.
Where did you get this solution?
@Grender, I don't remember exactly but I was searching on google and tried this also and It solved my issue. Did it solve your issue ?
Yes, it solved my issue, but it seems to be a weird workaround, hope it's a bug and it gets solved by Google.
|
0

Please use getMapAsync.

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

1 Comment

It is giving error in xml at <fragment, error: android.view.InflateException: Binary XML file : Error inflating class fragment
0

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>

Comments

0

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

Comments

0

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

public void onDestroy() {
    super.onDestroy();
    getFragmentManager().beginTransaction().remove(mapfragmentnamehere).commit();
}

Comments

-1
public void onMapReady(GoogleMap googleMap) {

    setUpMap(googleMap);

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.