1

i try to display map in my application, for first time I launch my application, everything is going fine untill I'm going to another page that display Map too. this is my code :

public class PKN_Frag_SummaryKabupaten extends Fragment{
private GoogleMap map;
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle saveInstanceState) {
        View Sum_Kab = inflater.inflate(R.layout.modul2_kabupaten, container,
                false);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
map.moveCamera(CameraUpdateFactory.newLatLngZoom(MAP_PUPI, 15));
        map.animateCamera(CameraUpdateFactory.zoomTo(0), 2000, null);
return Sum_Kab;

    }
    private GoogleMap getGoogleMap() {
         if (map == null && getActivity() != null && getActivity().getFragmentManager()!= null) {
             MapFragment smf = (MapFragment)getActivity().getFragmentManager().findFragmentById(R.id.map);
                if (smf != null) {
                    map = smf.getMap();
                }
            }
            return map;
    }
    @Override
    public void onDestroyView() 
     {
        super.onDestroyView(); 
        Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));  
        FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction();
        ft.remove(fragment);
        ft.commit();
    }

and this is my code for map :

 <fragment
                android:id="@+id/map"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_margin="10dp"
                class="com.google.android.gms.maps.MapFragment"/>

and this is what logcat said :

07-14 14:21:20.186: E/AndroidRuntime(29586): FATAL EXCEPTION: main
07-14 14:21:20.186: E/AndroidRuntime(29586): android.view.InflateException: Binary XML file line #251: Error inflating class fragment
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at id.go.kpp.aplikasipupi.pkn.PKN_Frag_SummaryKabupaten.onCreateView(PKN_Frag_SummaryKabupaten.java:115)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.app.BackStackRecord.run(BackStackRecord.java:635)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1401)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.os.Handler.handleCallback(Handler.java:615)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.os.Looper.loop(Looper.java:137)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.app.ActivityThread.main(ActivityThread.java:4895)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at java.lang.reflect.Method.invokeNative(Native Method)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at java.lang.reflect.Method.invoke(Method.java:511)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at dalvik.system.NativeStart.main(Native Method)
07-14 14:21:20.186: E/AndroidRuntime(29586): Caused by: java.lang.IllegalArgumentException: Binary XML file line #251: Duplicate id 0x7f06003e, tag null, or parent id 0x7f06003d with another fragment for com.google.android.gms.maps.MapFragment
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.app.Activity.onCreateView(Activity.java:4819)
07-14 14:21:20.186: E/AndroidRuntime(29586):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
07-14 14:21:20.186: E/AndroidRuntime(29586):    ... 20 more

I don't know where is my fault, because when I run in with extend Activity, there is no error or something wrong, is there anyone can help me?

UPDATE

this is what happen after I'm using MapView

enter image description here

Menma
  • 799
  • 1
  • 9
  • 35

1 Answers1

0

I had the same problem and managed to fix it by following Raghunandad's answer by adding MapView in my fragment as is stated in this answer stackoverflow.com/questions/20919048/. I also had a blank mapview at first because I did not set mapView.onResume(); mapView.onDestroy(); and mapView.onLowMemory();

I hope it will work for you too.

  @Override
    public void onResume() {
        mapView.onResume();
        super.onResume();
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }
    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mapView.onLowMemory();
    }
AncaS
  • 110
  • 7