Android 膨胀类片段时出错(第二次打开对话框时)

Android 膨胀类片段时出错(第二次打开对话框时),android,android-fragments,Android,Android Fragments,所以我在打开DialogFragment时遇到了这个错误。我第一次打开它就可以了,但是如果我缩小它,然后再尝试打开它,我就会出错。在添加GoogleMap片段以及将片段导入更改为android.support.v4.app.DialogFragment之后,才出现这种情况从导入android.app.DialogFragment 最近有人告诉我要在这里(android S.O.)添加更多代码,所以我从一开始就添加了一些。如果我做得太多,请告诉我 堆栈跟踪: 我如何调用该对话框: CreateJo

所以我在打开DialogFragment时遇到了这个错误。我第一次打开它就可以了,但是如果我缩小它,然后再尝试打开它,我就会出错。在添加GoogleMap片段以及将片段导入更改为
android.support.v4.app.DialogFragment之后,才出现这种情况从导入android.app.DialogFragment

最近有人告诉我要在这里(android S.O.)添加更多代码,所以我从一开始就添加了一些。如果我做得太多,请告诉我

堆栈跟踪: 我如何调用该对话框: CreateJobDialog: CreateJobXML

为了更好地衡量舱单:
我认为您的问题已在跟踪中的这一行确定:

原因:java.lang.IllegalArgumentException:二进制XML文件行#166:重复id 0x7f0e00b7、标记null或父id 0xffffffff与com.google.android.gms.maps.SupportMapFragment的另一个片段


检查您是否没有对片段重用ID,并且正确地取消了
对话框fragment
。请参阅此堆栈溢出和,以获取有关取消“DialogFragment”的信息。

我认为您的问题已在跟踪中的这一行确定:

原因:java.lang.IllegalArgumentException:二进制XML文件行#166:重复id 0x7f0e00b7、标记null或父id 0xffffffff与com.google.android.gms.maps.SupportMapFragment的另一个片段


检查您是否没有对片段重用ID,并且正确地取消了
对话框fragment
。请参阅此堆栈溢出和,以获取有关取消“DialogFragment”的信息。

最可能的情况是,在视图层次结构中(即在活动的xml本身中)有另一个
SupportMapFragment
膨胀。现在,您正试图在
对话框fragment
中使用相同的id
R.id.map
对新的进行充气。这是不可能发生的,因为在同一活动的视图层次结构中有两个具有相同id的视图

从错误跟踪中:

com.google.android.gms.maps.SupportMapFragment的重复id 0x7f0e00b7、标记null或父id 0xffffffff以及另一个片段

CreateJobXML
中更改
SupportMapFragment
的id:

<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>

...
...

最可能的情况是,在视图层次结构(即活动的xml本身)中有另一个
SupportMapFragment
膨胀。现在,您正试图在
对话框fragment
中使用相同的id
R.id.map
对新的进行充气。这是不可能发生的,因为在同一活动的视图层次结构中有两个具有相同id的视图

从错误跟踪中:

com.google.android.gms.maps.SupportMapFragment的重复id 0x7f0e00b7、标记null或父id 0xffffffff以及另一个片段

CreateJobXML
中更改
SupportMapFragment
的id:

<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>

...
...

更改名称不会结束错误,这让我相信可能我没有在取消对话框时销毁mapFragment更改名称不会结束错误,这让我相信可能我没有在取消对话框时销毁mapFragment
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");
    }
}
<?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>
<?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>
<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>