I am trying to use a MapFragment inside one of my DrawerLayout item.
My DrawerLayout:
private void selectItem(int position) {
switch (position) {
(...)
case 3:
fragment = new MyMapFragment();
break;
(...)
//THIS CODE WORKS WITH ANY OTHER FRAGMENT I CREATED!!!!!!
}
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();
This code works fine with all my Fragments and never crash, except for the MyMapFragment. This one (only this one) crash on device rotation while the code is very similar to my other Fragments.
The only difference is that I am using a nested Fragment:
public class MyMapFragment extends Fragment {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mMapFragment = new MapFragment();
GoogleMap map = mMapFragment.getMap();
FragmentTransaction fragmentTransaction =
getChildFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.container, mMapFragment);
fragmentTransaction.commit();
}
I don't what is wrong there...
Logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.*/com.*.MainActivity}: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.*.MyMapFragment$1: make sure class name exists, is public, and has an empty constructor that is public
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2194)