In my application homepage The google place
auto complete fragment
opens on a button press inside a dialog bar and the location is used for a search query. The problem is when I try to change the location by pressing the button again the application crashes with the following error.
*android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class fragment
Duplicate id 0x7f0e00db, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment*
This is the button press activity and the method that it calls.
case R.id.text_area:
EditLocation();
break;
private void EditLocation() {
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.area);
dialog.setTitle("Please enter the location");
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.autocomplete_fragment);
((EditText)autocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input)).setHint("Search Location");
//((EditText)autocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input)).setTextSize(10.0f);
//txtlocation=(TextView) findViewById(R.id.dialogLocationText);
autocompleteFragment.setOnPlaceSelectedListener(this);
Button dialogButtonSave = (Button) dialog.findViewById(R.id.btnOK);
// if button is clicked, close the custom dialog
dialogButtonSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//area=dialogLocation.getText().toString();
location.setText(area);
dialog.dismiss();
//autocompleteFragment.setText("");
}
});
dialog.show();
}
Following is the xml code
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_marginTop="10dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="10dp"
android:layout_weight=".335"
android:gravity="center"
android:textSize="13sp"
android:background="@android:color/white"
>
<fragment
android:id="@+id/autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
<Button
android:id="@+id/btnOK"
android:layout_width="350dp"
android:layout_margin="10dp"
android:layout_height="35dp"
android:text="OK"
android:background="@drawable/custom_btn_orange"/>
</LinearLayout>
Following are screenshots of how the button and fragment operate.
Following is the logcat
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.itcastle.kleanify, PID: 3659 android.view.InflateException: Binary XML file line #24: Binary XML file line #24: 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.Dialog.setContentView(Dialog.java:512) at com.itcastle.kleanify.WelcomeHomeTemp.EditLocation(WelcomeHomeTemp.java:533) at com.itcastle.kleanify.WelcomeHomeTemp.onClick(WelcomeHomeTemp.java:453) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) 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 #24: 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.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) at android.app.Dialog.setContentView(Dialog.java:512) at com.itcastle.kleanify.WelcomeHomeTemp.EditLocation(WelcomeHomeTemp.java:533) at com.itcastle.kleanify.WelcomeHomeTemp.onClick(WelcomeHomeTemp.java:453) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) 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 #24: Duplicate id 0x7f0e00db, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2205) 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:36) at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75) 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.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) at android.app.Dialog.setContentView(Dialog.java:512) at com.itcastle.kleanify.WelcomeHomeTemp.EditLocation(WelcomeHomeTemp.java:533) at com.itcastle.kleanify.WelcomeHomeTemp.onClick(WelcomeHomeTemp.java:453) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) 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) I/Process: Sending signal. PID: 3659 SIG: 9 Application terminated.
I have gone through many questions and almost everywhere the answer is to add some lines of code inside onDestroyView()
which I dont have. On the first click the fragment works perfectly, the problem is when I press the button again to change the location the application completely crushes. Any suggestion is appreciated. Thanks.