1
I am creating an application on Android in Eclipse with 3 screen with Swipe horizontal, in the last tab I have a Map Fragment.
But it turns out that when doing Swipe to the right the first time everything is normal, when doing a Swipe to the left and then going back to the right the application crashes and I get this error, which may be?
Thanks in advance
07-29 23:35:38.279: E/AndroidRuntime(10353): FATAL EXCEPTION: main
07-29 23:35:38.279: E/AndroidRuntime(10353): Process: com.sapires.JoesPizzariaGEN, PID: 10353
07-29 23:35:38.279: E/AndroidRuntime(10353): android.view.InflateException: Binary XML file line #8: Error inflating class fragment
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
07-29 23:35:38.279: E/AndroidRuntime(10353): at com.sapires.JoesPizzaria.Mapa.onCreateView(Mapa.java:16)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:482)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.support.v4.view.ViewPager$3.run(ViewPager.java:249)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.view.Choreographer.doCallbacks(Choreographer.java:603)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.view.Choreographer.doFrame(Choreographer.java:572)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.os.Handler.handleCallback(Handler.java:733)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.os.Handler.dispatchMessage(Handler.java:95)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.os.Looper.loop(Looper.java:136)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.app.ActivityThread.main(ActivityThread.java:5579)
07-29 23:35:38.279: E/AndroidRuntime(10353): at java.lang.reflect.Method.invoke(Native Method)
07-29 23:35:38.279: E/AndroidRuntime(10353): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
07-29 23:35:38.279: E/AndroidRuntime(10353): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
07-29 23:35:38.279: E/AndroidRuntime(10353): Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f070016, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.app.Activity.onCreateView(Activity.java:5002)
07-29 23:35:38.279: E/AndroidRuntime(10353): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
07-29 23:35:38.279: E/AndroidRuntime(10353): ... 25 more
Layout of Fragment
Map
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<fragment
android:id="@+id/fragment"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</LinearLayout>
Class
package com.sapires.JoesPizzaria;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class TabPagerAdapter extends FragmentStatePagerAdapter {
public TabPagerAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public Fragment getItem(int i) {
switch (i) {
case 0:
return new APizzaria();
case 1:
return new Ementa();
case 2:
return new Mapa();
}
return null;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 3; //No of Tabs
}
}
Place the layout of
Fragment
Mapa
. How are the fragments being removed and inserted? Are you sure you are not leaving two equal fragments in theActivity
?– Wakim
Include these codes by editing your question, it becomes more readable.
– Wakim
Okay, I added to the question, thank you
– SaPires
I recommend doing the following, take out the
id
of<fragment>
and use tag. To recover thefragment
, use thefindFragmentByTag
ofFragmentManager
.– Wakim
can exemplify pf, what is tag? Thank you
– SaPires
I’ve had these problems before, and as a tag is a way to uniquely identify a fragment instance as well as the id, I have my doubts if it will resolve. The case is that the application is trying to add to Fragmentmanager two instances of Mapfragment identified in the same way, which is not allowed. It would be the case to increase offscreenPageLimit or remove Mapfragment from Fragmentmanager before adding another instance of it.
– Piovezan
So how can I fix?
– SaPires
I’ll explain in a reply, Father.
– Piovezan
this is the project: https://www.dropbox.com/s/7xozvj40uezkmg7/SwipeTab.rar
– SaPires