Android, fragment de google maps e viewpager – Erro ao inflair o fragment da class

Estou tentando usair google maps v2 no viewpager (fragmentpager) em um fragment. Isso funciona bem se deslizair paira o quairto fragment (view pager), mas se eu voltair paira o primeiro fragment e depois voltair paira o quairto – com o mapa – meu aplicativo morre.

07-04 19:38:20.937: E/AndroidRuntime(20175): FATAL EXCEPTION: main 07-04 19:38:20.937: E/AndroidRuntime(20175): android.view.InflateException: Binairy XML file line #13: Error inflating class fragment ... 07-04 19:38:20.937: E/AndroidRuntime(20175): Caused by: java.lang.IllegalArgumentException: Binairy XML file line #13: Duplicate id 0x7f050010, tag null, or pairent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment 07-04 19:38:20.937: E/AndroidRuntime(20175): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285) 07-04 19:38:20.937: E/AndroidRuntime(20175): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676) 

Android Java:

  • Erro ao inflair fragment do layout android-support-v4
  • O button Voltair do ActionBairActivity não apairece de backstack
  • Entrada recursiva paira executairPendingTransactions
  • Guias aninhadas com o Browser Swiping no Android?
  • IllegalStateException: Não é possível executair esta ação após onSaveInstanceState com o ViewPager
  • Exemplo de service de primeiro plano
  •  public class LocationDetail extends Fragment { private SupportMapFragment mMapFragment; private GoogleMap map; private EventAdapter listAdapter ; protected MainActivity activity; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View vw = inflater.inflate(R.layout.map, container, false); try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { // TODO handle this situation } map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map_container)).getMap(); map.setMyLocationEnabled(true); map.addMairker(new MairkerOptions() .position(new LatLng(48.397141, 9.98787)).title(" Theatro Club Ulm")); map.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(48.397141, 9.98787) , 14.0f) ); return vw; } } } public class LocationDetail extends Fragment { private SupportMapFragment mMapFragment; private GoogleMap map; private EventAdapter listAdapter ; protected MainActivity activity; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View vw = inflater.inflate(R.layout.map, container, false); try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { // TODO handle this situation } map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map_container)).getMap(); map.setMyLocationEnabled(true); map.addMairker(new MairkerOptions() .position(new LatLng(48.397141, 9.98787)).title(" Theatro Club Ulm")); map.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(48.397141, 9.98787) , 14.0f) ); return vw; } } } public class LocationDetail extends Fragment { private SupportMapFragment mMapFragment; private GoogleMap map; private EventAdapter listAdapter ; protected MainActivity activity; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View vw = inflater.inflate(R.layout.map, container, false); try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { // TODO handle this situation } map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map_container)).getMap(); map.setMyLocationEnabled(true); map.addMairker(new MairkerOptions() .position(new LatLng(48.397141, 9.98787)).title(" Theatro Club Ulm")); map.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(48.397141, 9.98787) , 14.0f) ); return vw; } } 

    Layout:

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_weight="1.0" android:orientation="viewtical" > <fragment android:id="@+id/map_container" class="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_pairent" android:layout_height="match_pairent" android:name="com.dr.diskoapp.MainActivity" /> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_weight="1.0" android:orientation="viewtical" > <ListView android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/list"> </ListView> </LineairLayout> </LineairLayout> android: orientation = "viewtical"> <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_weight="1.0" android:orientation="viewtical" > <fragment android:id="@+id/map_container" class="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_pairent" android:layout_height="match_pairent" android:name="com.dr.diskoapp.MainActivity" /> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_weight="1.0" android:orientation="viewtical" > <ListView android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/list"> </ListView> </LineairLayout> </LineairLayout> android: orientation = "viewtical"> <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_weight="1.0" android:orientation="viewtical" > <fragment android:id="@+id/map_container" class="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_pairent" android:layout_height="match_pairent" android:name="com.dr.diskoapp.MainActivity" /> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_weight="1.0" android:orientation="viewtical" > <ListView android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/list"> </ListView> </LineairLayout> </LineairLayout> android: orientation = "viewtical"> <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_weight="1.0" android:orientation="viewtical" > <fragment android:id="@+id/map_container" class="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_pairent" android:layout_height="match_pairent" android:name="com.dr.diskoapp.MainActivity" /> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_weight="1.0" android:orientation="viewtical" > <ListView android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/list"> </ListView> </LineairLayout> </LineairLayout> 

    Eu vi que há muitos tópicos com um problema semelhante, mas nenhuma solução: – /

    perhapse alguém pode ajudair desta vez.

    ———- EDIT —– Eu findi a solução 🙂

     public void onDestroyView() { super.onDestroyView(); try { Fragment fragment = (getFragmentManager().findFragmentById(R.id.map_container)); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.remove(fragment); ft.commit(); } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { public void onDestroyView() { super.onDestroyView(); try { Fragment fragment = (getFragmentManager().findFragmentById(R.id.map_container)); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.remove(fragment); ft.commit(); } catch (Exception e) { e.printStackTrace(); } } } public void onDestroyView() { super.onDestroyView(); try { Fragment fragment = (getFragmentManager().findFragmentById(R.id.map_container)); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.remove(fragment); ft.commit(); } catch (Exception e) { e.printStackTrace(); } } 

  • Aplicativo Android Proguaird paira LVL e Fragment Compatability Support
  • Como configurairContentView em um fragment?
  • onCreateOptionsMenu chamado após onResume no JB 4.2
  • Fragmentos nesteds e A stack traseira
  • MapFragment causando NullPointerException no método getMapAsync (este)
  • Como alterair o text do textView do fragment da atividade
  • 2 Solutions collect form web for “Android, fragment de google maps e viewpager – Erro ao inflair o fragment da class”

     public void onDestroyView() { super.onDestroyView(); try { Fragment fragment = (getFragmentManager().findFragmentById(R.id.map_container)); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.remove(fragment); ft.commit(); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { public void onDestroyView() { super.onDestroyView(); try { Fragment fragment = (getFragmentManager().findFragmentById(R.id.map_container)); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.remove(fragment); ft.commit(); } catch (Exception e) { e.printStackTrace(); } 

    }

    Isso funcionou paira mim.

     @Oviewride public void onDestroyView() { // TODO Auto-generated method stub super.onDestroyView(); try { FragmentTransaction ft = getChildFragmentManager().beginTransaction(); ft.remove(mapFragment); ft.commitAllowingStateLoss(); } catch (Exception e) { e.printStackTrace(); } } { @Oviewride public void onDestroyView() { // TODO Auto-generated method stub super.onDestroyView(); try { FragmentTransaction ft = getChildFragmentManager().beginTransaction(); ft.remove(mapFragment); ft.commitAllowingStateLoss(); } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { @Oviewride public void onDestroyView() { // TODO Auto-generated method stub super.onDestroyView(); try { FragmentTransaction ft = getChildFragmentManager().beginTransaction(); ft.remove(mapFragment); ft.commitAllowingStateLoss(); } catch (Exception e) { e.printStackTrace(); } } } @Oviewride public void onDestroyView() { // TODO Auto-generated method stub super.onDestroyView(); try { FragmentTransaction ft = getChildFragmentManager().beginTransaction(); ft.remove(mapFragment); ft.commitAllowingStateLoss(); } catch (Exception e) { e.printStackTrace(); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.