1

So I've run into this error when opening my DialogFragment. It is fine the first time I open it but If I dimiss it and then try to open it again I run into errors. This wasn't occurring untill after adding the GoogleMap fragment as well as change the fragment import to android.support.v4.app.DialogFragment; from import android.app.DialogFragment;

I've been being told to include more code lately here (in the android S.O.) so I added a bit from the start. Let me know if I over did it.

StackTrace:

   FATAL EXCEPTION: main
 Process: com.example.andrew.neighborlabour, PID: 9528
 android.view.InflateException: Binary XML file line #166: Binary XML file line #166: 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.example.andrew.neighborlabour.CreateJobDialog.onCreateView(CreateJobDialog.java:77)
     at android.support.v4.app.Fragment.performCreateView(Fragment.java:2189)
     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
     at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
     at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:757)
     at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2355)
     at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2146)
     at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2098)
     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2008)
     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)
     at android.os.Handler.handleCallback(Handler.java:739)
     at android.os.Handler.dispatchMessage(Handler.java:95)
     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 #166: 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.rInflate(LayoutInflater.java:838)
     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
     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.example.andrew.neighborlabour.CreateJobDialog.onCreateView(CreateJobDialog.java:77) 
     at android.support.v4.app.Fragment.performCreateView(Fragment.java:2189) 
     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299) 
     at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528) 
     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595) 
     at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:757) 
     at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2355) 
     at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2146) 
     at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2098) 
     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2008) 
     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710) 
     at android.os.Handler.handleCallback(Handler.java:739) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     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.IllegalArgumentException: Binary XML file line #166: Duplicate id 0x7f0e00b7, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
     at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3420)
     at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
     at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:378)
     at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
     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.rInflate(LayoutInflater.java:838) 
     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
     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.example.andrew.neighborlabour.CreateJobDialog.onCreateView(CreateJobDialog.java:77) 
     at android.support.v4.app.Fragment.performCreateView(Fragment.java:2189) 
     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299) 
     at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528) 
     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595) 
     at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:757) 
     at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2355) 
     at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2146) 
     at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2098) 
     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2008) 
     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710) 
     at android.os.Handler.handleCallback(Handler.java:739) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     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) 

How I am calling the Dialog:

new CreateJobDialog().show(getSupportFragmentManager(), null);

CreateJobDialog:

import android.app.DatePickerDialog;
import android.os.Handler;
import android.support.v4.app.DialogFragment;
import android.app.FragmentTransaction;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.InflateException;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.example.andrew.neighborlabour.Services.Utils.Conversions;
import com.example.andrew.neighborlabour.Services.Utils.SuccessCB;
import com.example.andrew.neighborlabour.Services.listings.Listing;
import com.example.andrew.neighborlabour.Services.listings.ListingManager;
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;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class CreateJobDialog extends DialogFragment implements OnMapReadyCallback{

    public final static String EXTRA_MESSAGE = "CreateJob";
    private final String TAG = "Create Job Dialog";

    final int MAX_DURATION = 4 * 8; //in 15 minute intervals
    final int MAX_COMPENSATION = 100;

    View view;

    DatePickerDialog datePicker;
    TimePickerDialog timePicker;

    TextView etTitle;
    TextView etDescription;
    TextView etAddress;
    TextView tvCompensation;
    TextView tvDuration;
    TextView tvStartDate;
    TextView tvStartTime;

    GoogleMap map;

    Button btCreate;

    Calendar calendar = Calendar.getInstance();
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    int hour = 12;
    int minute = 0;

    int duration = 15;
    int compensation = 10;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.dialog_create_job, null);

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

        setUpGui(view);
        initTextValues();
        setButtonListeners();

        return view;
    }

    void setUpGui(View view){
        etTitle = (TextView)  view.findViewById(R.id.etTitle);
        etDescription = (TextView)  view.findViewById(R.id.etDescription);
        etAddress = (TextView)  view.findViewById(R.id.etAddress);
        tvCompensation = (TextView)  view.findViewById(R.id.tvCompensation);
        tvDuration = (TextView)  view.findViewById(R.id.tvDuration);
        tvStartDate = (TextView)  view.findViewById(R.id.tvStartDate);
        tvStartTime = (TextView)  view.findViewById(R.id.tvStartTime);
        btCreate = (Button) view.findViewById(R.id.btCreate);
    }

    void initTextValues(){
        tvStartDate.setText( (month+1) + "/" + day + "/" + year);
        tvStartTime.setText( "12:00");
        tvCompensation.setText("$10");
        tvDuration.setText("0:15");
    }

    void setButtonListeners(){
        tvStartDate.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                //showStartDatePicker();
            }
        });
        tvDuration.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                //showDurationPicker();
            }
        });
        tvStartTime.setOnClickListener( new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                //showTimePicker();
            }
        });
        tvCompensation.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                //showCompensationPicker();
            }
        });
        btCreate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //createJob();
            }
        });
        etAddress.setOnFocusChangeListener(new View.OnFocusChangeListener(){
            @Override
            public void onFocusChange(View view, boolean b) {
                //updateMap();
            }
        });
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        map = googleMap;
        Log.e("map", "ready");
    }
}

CreateJobXML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.andrew.neighborlabour.CreateJobDialog">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tvTitle"
            android:text="Create Job"
            android:textAppearance="@color/colorPrimaryDark"
            android:textSize="24dp"
            android:padding="20dp"
            android:lines="2"
            android:layout_gravity="left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </TextView>

    </LinearLayout>

    <ScrollView android:id="@+id/ScrollView01"
        android:layout_width="fill_parent"
        android:layout_height="400dp">

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

            <EditText
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingBottom="20dp"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="Job Title"
                android:id="@+id/etTitle"/>

            <EditText
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingBottom="20dp"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="Address"
                android:id="@+id/etAddress"/>

            <EditText
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingBottom="20dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Description"
                android:lines="3"
                android:id="@+id/etDescription"/>

            <LinearLayout
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingBottom="20dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width = "300dp"
                    android:text="Compensation: "
                    android:layout_weight="1"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvCompensation"
                    android:textAlignment="textEnd"
                    android:layout_gravity="end"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1" />

            </LinearLayout>


            <LinearLayout
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingBottom="20dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width = "300dp"
                    android:text="Duration: "
                    android:layout_weight="1"
                    android:layout_height="wrap_content" />

                <TextView
                    android:textAlignment="textEnd"
                    android:layout_gravity="end"
                    android:layout_width="300dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:id="@+id/tvDuration"/>

            </LinearLayout>

            <LinearLayout
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingBottom="20dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width = "300dp"
                    android:text="Date: "
                    android:layout_weight="1"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvStartDate"
                    android:textAlignment="textEnd"
                    android:layout_gravity="end"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1" />

            </LinearLayout>

            <LinearLayout
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingBottom="20dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width = "300dp"
                    android:text="Time: "
                    android:layout_weight="1"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvStartTime"
                    android:textAlignment="textEnd"
                    android:layout_gravity="end"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1" />

            </LinearLayout>

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

        </LinearLayout>

    </ScrollView>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Create Job"
        android:id="@+id/btCreate"
        android:onClick="Create"/>

</LinearLayout>

And for good measure the Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.andrew.neighborlabour">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


    <application
        android:name=".ParseProject"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AIzaSyB151f1l-Rr5H3jWNYTTWlIFklHbDpGchg"/>

        <activity
            android:name=".UI.auth.LoginActivity"
            android:label="login">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".MainActivity">
        </activity>
        <activity
            android:name=".UI.jobListings.ListingDetailActivity"
            android:theme="@android:style/Theme.Dialog">
        </activity>
        <activity
            android:name=".UI.auth.RegisterActivity">
        </activity>
        <activity
            android:name=".UI.auth.ProfileActivity">
        </activity>

    </application>

</manifest>
Chris Chevalier
  • 620
  • 1
  • 7
  • 20

2 Answers2

0

I think that you problem is identified at this line in the trace:

Caused by: java.lang.IllegalArgumentException: Binary XML file line #166: Duplicate id 0x7f0e00b7, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment

Check that you are not reusing ids for fragments and are properly dismissing your DialogFragment. See this Stack Overflow question and the documentation for info on dismissing `DialogFragment's.

Community
  • 1
  • 1
Cheticamp
  • 61,413
  • 10
  • 78
  • 131
0

Most possibly you have another SupportMapFragment inflated in the view hierarhy (i.e. in the activity's xml itself). Now you are trying to inflate a new one with the same id R.id.map in the DialogFragment. That cannot happen, because it would turn out there are two views with the same id in the same activity's view hierarchy.

From the error stacktrace:

Duplicate id 0x7f0e00b7, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment

Change the id of SupportMapFragment in the CreateJobXML:

<LinearLayout>
...
    <fragment   android:layout_width="match_parent"
                android:layout_height="200dp"
                android:id="@+id/map1" // another id
                tools:context=".MapsActivity"
                android:name="com.google.android.gms.maps.SupportMapFragment" />
...
</LinearLayout>
azizbekian
  • 60,783
  • 13
  • 169
  • 249
  • Changing the name doesn't end the errors which makes me believe maybe I'm not destroying my mapFragment on dismissal of the dialog – Chris Chevalier Mar 23 '17 at 14:25