javaandroidgoogle-mapsandroid-fragmentsinflate-exception

Google Maps Error Inflating Class Fragment Android


I have been searching the web and cannot seem to find an answer that works for me. I recently made a new project in Android Simulator and chose the Google Maps Template. I followed the instructions at https://developers.google.com/maps/documentation/android-api/start to make sure I had done everything right the first time. To my disgrace, I get the same error.

Firstly, here is my MapsActivity.java:

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

Secondly, my activity_maps.xml:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.xenicdev.mapstest.MapsActivity" />

And finally, my error:

05-13 19:47:40.542 3052-3052/com.xenicdev.mapstest E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xenicdev.mapstest, PID: 3052
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xenicdev.mapstest/com.xenicdev.mapstest.MapsActivity}: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 Caused by: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment
 at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
 at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
 at android.app.Activity.setContentView(Activity.java:2166)
 at com.xenicdev.mapstest.MapsActivity.onCreate(MapsActivity.java:20)
 at android.app.Activity.performCreate(Activity.java:6237)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
 at android.os.Handler.dispatchMessage(Handler.java:102) 
 at android.os.Looper.loop(Looper.java:148) 
 at android.app.ActivityThread.main(ActivityThread.java:5417) 
 at java.lang.reflect.Method.invoke(Native Method) 
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
 Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
 at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
 at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
 at android.app.Activity.setContentView(Activity.java:2166) 
 at com.xenicdev.mapstest.MapsActivity.onCreate(MapsActivity.java:20) 
 at android.app.Activity.performCreate(Activity.java:6237) 
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
 at android.os.Handler.dispatchMessage(Handler.java:102) 
 at android.os.Looper.loop(Looper.java:148) 
 at android.app.ActivityThread.main(ActivityThread.java:5417) 
 at java.lang.reflect.Method.invoke(Native Method) 
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.mkdir()' on a null object reference
 at com.google.maps.api.android.lib6.gmm6.m.ad.a(Unknown Source)
 at com.google.maps.api.android.lib6.gmm6.c.h.a(Unknown Source)
 at com.google.maps.api.android.lib6.gmm6.c.y.a(Unknown Source)
 at com.google.maps.api.android.lib6.e.bd.a(Unknown Source)
 at com.google.maps.api.android.lib6.e.ev.a(Unknown Source)
 at com.google.maps.api.android.lib6.e.z.a(Unknown Source)
 at com.google.maps.api.android.lib6.e.y.a(Unknown Source)
 at com.google.android.gms.maps.internal.u.onTransact(SourceFile:107)
 at android.os.Binder.transact(Binder.java:387)
 at com.google.android.gms.maps.internal.IMapFragmentDelegate$zza$zza.onCreateView(Unknown Source)
 at com.google.android.gms.maps.SupportMapFragment$zza.onCreateView(Unknown Source)
 at com.google.android.gms.dynamic.zza$4.zzb(Unknown Source)
 at com.google.android.gms.dynamic.zza.zza(Unknown Source)
 at com.google.android.gms.dynamic.zza.onCreateView(Unknown Source)
 at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
 at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1036)
 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1230)
 at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1332)
 at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2288)
 at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
 at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
 at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
 at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
 ... 19 mo

Solution

  • I have not found a true answer to my problem except that after the Google API had updated, I made a new project that worked. I cannot explain what the cause was for this error but have found that the only workaround for me was to wait for the next Google API update and start a new project.