1

in my application i'm loading map in navigation drawer fragment class. first time when i'm opening map fragment its showing me map but on second time following fatal exception-

E/AndroidRuntime(5881): java.lang.IllegalArgumentException: No view found for id 0x7f050025 (com.example.myapp:id/mapfragment) for fragment Fragment{41d89968 #1 id=0x7f050025}

xml code-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/mapfragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.MapFragment" />

</LinearLayout>

java code-

View v;
Fragment mf;
MapFragment m;
private GoogleMap map;
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
try {
            //Fragment videoFragment = new DealerLocations();
            v = inflater.inflate(R.layout.map, container, false);
        } catch (InflateException e) {
        }
Fragment mf = new Fragment();
        mf.getFragmentManager();
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.mapfragment, mf).commit();

        m= (MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.mapfragment);
        map = m.getMap();
}

I also wend through many links like- When inflating fragment which was previously inflated app crashes , Android, java.lang.IllegalArgumentException: No view found for id [..] for fragment [..] but not getting solution. Is there any solution for this?

Community
  • 1
  • 1
yuva ツ
  • 3,707
  • 9
  • 50
  • 78
  • I have already added that part.see my question again.first time when i select option my activity for map its showing me map..but when second time giving exception – yuva ツ Feb 01 '14 at 10:25
  • sorry that is not he mistake. Your error is here `fragmentManager.beginTransaction().replace(R.id.mapfragment, mf).commit()`; Your log says `No view found for fragment` can't find `id/mapfragment`. – Raghunandan Feb 01 '14 at 10:29
  • whats the mistake then?what should i do?? – yuva ツ Feb 01 '14 at 10:31
  • Use intrface as a callback to the activity and from activity replace existing fragment with new one – Raghunandan Feb 01 '14 at 10:32
  • 1
    you should use MapView if you want map in `fragment` – Raghunandan Feb 01 '14 at 10:33
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/46581/discussion-between-raghunandan-and-yuva) – Raghunandan Feb 01 '14 at 10:34
  • but i'm adding polyline on google map.thats why i'm using it.i can't use mapview – yuva ツ Feb 01 '14 at 10:37

1 Answers1

0

Perhaps you could try this:

m= (MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.mapfragment);
map = m.getMap();

getActivity().getFragmentManager().beginTransaction().replace(R.id.mapfragment, mf).commit();