title: How to properly initialize map?
body: <p>How do I initialize my map in my fragment? I'm getting a nullpointerexception right now. I have a fragment, <em>Fragment01</em>, which is only to display the map and a layout, <em>Fragment_01.xml</em>, which only contains the map.</p>
  
  <p><strong>Manifest</strong>
      
      </p>
  
  <pre><code>&lt;uses-sdk
      android:minSdkVersion="11"
      android:targetSdkVersion="19" /&gt;
  
  &lt;permission
  android:name="se.sebastianliljegren.nellienovafoto.permission.MAPS_RECEIVE"
  android:protectionLevel="signature"/&gt;
  
  &lt;uses-permission android:name="se.sebastianliljegren.nellienovafoto.permission.MAPS_RECEIVE"/&gt;
  &lt;library
      android:name="com.google.android.maps"
      /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/&gt;
  &lt;!-- The following two permissions are not required to use
   Google Maps Android API v2, but are recommended. --&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
  
  &lt;uses-feature
      android:glEsVersion="0x00020000"
      android:required="true"/&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
  
      &lt;meta-data
  android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version" /&gt;
  
      &lt;meta-data
  android:name="com.google.android.maps.v2.API_KEY"
  android:value="############################"/&gt;
  
      &lt;activity
          android:name="se.sebastianliljegren.nellienovafoto.MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>MainActivity</strong>
      public class MainActivity extends FragmentActivity {</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      FragmentManager fm = getSupportFragmentManager();
      FragmentTransaction transaction = fm.beginTransaction();
      StartFragment startfragment = new StartFragment();
  
      transaction.add(R.id.fragment_placeholder, startfragment);
      transaction.commit();
  }
  
  public void onSelectFragment(View view){
  
      Fragment newFragment;
  
      if (view == findViewById(R.id.btnomforetaget)) {
          newFragment = new StartFragment();
      } else if (view == findViewById(R.id.btnhittahit)) {
          newFragment = new Fragment01();
      } else if (view == findViewById(R.id.btnhemsida)) {
          newFragment = new Fragment02();
      } else {
          newFragment = new StartFragment();
      }
  
      FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
      transaction.replace(R.id.fragment_placeholder, newFragment);
      transaction.addToBackStack(null);
      transaction.commit();
  
  }
  
  }
  </code></pre>
  
  <p><strong>Fragment01</strong></p>
  
  <pre><code>public class Fragment01 extends Fragment {
  MapView mapView;
  GoogleMap map;
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View view = inflater.inflate(R.layout.fragment_01, container, false);
  
  LatLng sydney = new LatLng(-33.867, 151.206);
  
  map.setMyLocationEnabled(true);
  map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
  
  map.addMarker(new MarkerOptions()
      .title("Sydney")
      .snippet("The most populous city in Australia.")
      .position(sydney));
  
  return view;
  }
  
  @Override
  public void onDestroyView()
  {
    super.onDestroyView();
     Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));  
    FragmentTransaction ft =     getActivity().getSupportFragmentManager().beginTransaction();
    ft.remove(fragment);
    ft.commit();
  
  }
  
  }
  </code></pre>
  
  <p><strong>Fragment_01.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:id="@+id/fragment02"&gt;
  &lt;fragment android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="com.google.android.gms.maps.MapFragment"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>