0

I'm getting a NullPointerException in the onCreateView method of my fragment but what is strange is that this only occurrs on the emulator. On the device the app runs fine.

If I set a breakpoint for NullPointerException and debug in eclipse it stops at this line:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_map, container, false);

        mapTrackButton = (Button) rootView.findViewById(R.id.track_user_button);

        map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

        map.setMyLocationEnabled(true); // This line
        // More code

    }
Peter Warbo
  • 11,136
  • 14
  • 98
  • 193

1 Answers1

1

I think google maps is not available on emulator.

To fix error do this:

if (map != NULL) {
    map.setMyLocationEnabled(true);
    // ...
}
muktupavels
  • 348
  • 4
  • 14
  • 1
    To be more specific, the emulator does not support the Google Play services which has the Google Maps API unless it is running 4.2.2 or higher. http://stackoverflow.com/a/14536645/634474 – dymmeh Feb 26 '14 at 14:41
  • But my emulator is running 4.4.2? – Peter Warbo Feb 26 '14 at 14:45
  • 1
    Are you using 'Android 4.2.2 - API Level 19' or 'Google APIs (Google Inc.) - API Level 19'? From dymmeh link seems that you need to use 'Google APIs (Google Inc.) - API Level 19'. – muktupavels Feb 26 '14 at 14:51
  • Thanks for your suggestions, it turned out that I din't use the Google APIs on the emulator... – Peter Warbo Feb 27 '14 at 08:45