1

I have a fragment activity as seen in my last question:

App crashing when using fragments

It crushes because of a GoogleMap inside one of my fragments (MainActivity).

right now thats the code:

private GoogleMap map;

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

I cant change GoogleMap. it causes other problems in my code as im using it.

What should I do?

Thanks for your assistance!

Ive tried to relocate that piece of code to onCreateView. Doesn't work either.

Community
  • 1
  • 1
mn6vdv23g
  • 734
  • 2
  • 10
  • 33
  • Use LogCat to examine the Java stack trace associated with your "crush". – CommonsWare Sep 29 '13 at 22:12
  • Can you give more information, for example, where is this line in your code, in `onCreate`? Which type of error are you getting? – betorcs Sep 29 '13 at 22:12
  • @CommonsWare I already know what caused it.. its the GoogleMap. a fragment within a fragment. – mn6vdv23g Sep 29 '13 at 22:12
  • @betorcs this code, is inside a fragment. this fragment is used by a `FragmentActivity`. it crashes because one fragment cant be nested into another one. But it actually possiable. I just cant do that right - if I change `GoogleMap` it causes other errors... – mn6vdv23g Sep 29 '13 at 22:15
  • I see. If you want You can add a fragment inside other using getChildFragmentManager() http://developer.android.com/reference/android/support/v4/app/Fragment.html#getChildFragmentManager(). And the errors you are getting maybe because of GoogleMap lifecycle, make sure, you are getting it after onCreate. – betorcs Sep 29 '13 at 22:40
  • @betorcs I still dont get it.: `Cannot cast from Fragment to MapFragment` – mn6vdv23g Sep 30 '13 at 07:04
  • Have you inserted the map class (With package9 in the xml file? – dwbrito Feb 20 '14 at 17:53

0 Answers0