androidgoogle-mapsandroid-studiofragmentmapfragment

Android Studio : Error inflating class fragment


I'm writing an android app that includes a google map fragment. When I exclude the map fragment from the activity it's contained in, the app runs fine. When I include the map fragment, I get the exception quoted in the blockquote below. The most annoying part about this is that just a few weeks ago this did not happen. This activity ran perfectly fine for weeks and then I updated android studio and now I'm getting this exception. I've searched google and several threads on stackoverflow for solutions, nothing works. I even tried outright copy and pasting the google android demo for a map activity, and I get the same exception. PLEASE HELP.

The exception raised (copied from android monitor):

FATAL EXCEPTION: main Process: com.androidapps.seanmcalinden.firstandroidapp, PID: 23089 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidapps.seanmcalinden.firstandroidapp/com.androidapps.seanmcalinden.firstandroidapp.MapsActivity}: android.view.InflateException: Binary XML file line #55: Binary XML file line #55: 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 #55: Binary XML file line #55: 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.androidapps.seanmcalinden.firstandroidapp.MapsActivity.onCreate(MapsActivity.java:67) 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 #55: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 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.androidapps.seanmcalinden.firstandroidapp.MapsActivity.onCreate(MapsActivity.java:67)  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.MapFragment$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.MapFragment.onCreateView(Unknown Source) at android.app.Fragment.performCreateView(Fragment.java:2220) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:949) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126) at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1228) at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2201) at android.app.FragmentController.onCreateView(FragmentController.java:98) at android.app.Activity.onCreateView(Activity.java:5546) at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:34) at android.support.v4.app.FragmentActivity.onCreat

The OnCreate method:

    protected void onCreate(Bundle savedInstanceState) {
    Log.e("success", "entered onCreate in MapsActivity");

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    MapFragment mapFragment =
            (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    if (locationGAC == null) {
        // ATTENTION: This "addApi(AppIndex.API)"was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        locationGAC = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .addApi(AppIndex.API).build();
        Log.e("success", "created locationGAC");
    }

    Log.d("myTag", "test output 1");

    createFriendList();

}

The layout file for this activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@color/colorPrimary"
android:weightSum="1" >

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" >

    <Button
        android:layout_width="70dp"
        android:layout_height="60dp"
        android:text="Back"
        android:id="@+id/button"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignBottom="@+id/SearchBar1"
        android:onClick="backToLogin"
        android:background="@color/colorPrimaryDark"
        android:textColor="#ffffff" />

    <EditText
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:id="@+id/SearchBar1"
        android:layout_alignParentTop="true"
        android:hint="Search"
        android:layout_alignParentEnd="false"
        android:layout_alignParentStart="false"
        android:layout_toEndOf="@id/button"
        android:layout_toStartOf="@+id/SearchButton"
        android:textColor="#ffffff"
        android:textColorHint="#ffffff" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="70dp"
        android:layout_height="60dp"
        android:text="Go"
        android:id="@+id/SearchButton"
        android:layout_alignParentRight="true"
        android:enabled="true"
        android:onClick="onSearch"
        android:textColor="#ffffff"
        android:background="@color/colorPrimaryDark" />

</RelativeLayout>

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
    tools:context=".MapsActivity"
class="com.google.android.gms.maps.MapFragment" />


<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="60dp"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal">

    <Button
        android:layout_width="70dp"
        android:layout_height="60dp"
        android:text="Retrieve"
        android:id="@+id/serverRetrieveButton"
        android:layout_gravity="left"
        android:textColor="#ffffff"
        android:onClick="getLocationFromDexelus"
        android:background="@color/colorPrimaryDark" />

    <Button
        android:layout_width="70dp"
        android:layout_height="60dp"
        android:text="Send"
        android:id="@+id/serverSendButton"
        android:layout_alignParentRight="true"
        android:textColor="#ffffff"
        android:onClick="sendLocationToDexelus"
        android:background="@color/colorPrimaryDark" />

</RelativeLayout>

</RelativeLayout>

As said above, I've tried many solutions found here on Stackoverflow. Not to say that you shouldn't post those again, but rather that I think my issue may be more complex or specific than those because none of the given solutions worked for me.

Thanks.


Solution

  • For some reason when I updated my sdk to the version released on Wednesday, my issues disappeared. I guess this is appropriate since the issues first appeared after an android studio update. Thanks for your suggestions!