title: Android implement Google maps with fragment
body: <p>Hi I'm trying to implement the google map in my android application (Android Studio) after the google tutorial here : 
  <a href="https://developers.google.com/maps/documentation/android-api/map#mapfragment" rel="nofollow">https://developers.google.com/maps/documentation/android-api/map#mapfragment</a></p>
  
  <p>Here is my layout file  (I have added Google play services and api key, there seem to be no error this concerning.)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@drawable/background1000px"
      android:paddingBottom="0dp"
      android:paddingLeft="0dp"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.zuercher.zuerchertechnik.Display_product"&gt;
  
  &lt;TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@drawable/box400x50"
      android:id="@+id/title"
      android:layout_marginLeft="@dimen/activity_horizontal_margin"
      android:adjustViewBounds="true"
      android:layout_alignParentTop="true"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"
      android:layout_alignParentEnd="false"
      android:layout_alignParentRight="false"
      android:text="@string/kontakt"
      android:padding="10dp"
      android:textColor="@color/black"
      android:textSize="24sp"
      android:paddingTop="5dp"
  
      /&gt;
  
  &lt;fragment
      class="com.google.android.gms.maps.MapFragment"
      android:id="@+id/map2"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/&gt;
   &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And here is my java code for the activity : </p>
  
  <pre><code>package com.zuercher.zuerchertechnik;
  
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import com.google.android.gms.maps.GoogleMap;
  import com.google.android.gms.maps.GoogleMapOptions;
  import com.google.android.gms.maps.MapFragment;
  import com.google.android.gms.maps.OnMapReadyCallback;
  import com.google.android.gms.maps.SupportMapFragment;
  import com.google.android.gms.maps.model.CameraPosition;
  import com.google.android.gms.maps.model.LatLng;
  
  public class Display_contact extends FragmentActivity implements OnMapReadyCallback {
  
  @Override
  
  protected void onCreate( Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_display_contact);
      MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map2);
      mapFragment.getMapAsync(this);
  }
  
  @Override
  public void onMapReady(GoogleMap googleMap) {
  
  
  
  }
  }
  </code></pre>
  
  <p>I'm always getting the almose famous null pointer exception and really have tried a lot of different combinations but I'm getting desperate here.. (Surprisingly following the google tutorial didn't help at all...)
  What am I missing here?</p>
  
  <p>Thanks</p>
  
  <p>New added stacktrace code</p>
  
  <pre><code>FATAL EXCEPTION: main
                                                                                  Process: com.zuercher.zuerchertechnik, PID: 19745
                                                                            java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zuercher.zuerchertechnik/com.zuercher.zuerchertechnik.Display_contact}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.MapFragment.getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)' on a null object reference
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2656)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2721)
                                                                                at android.app.ActivityThread.access$900(ActivityThread.java:168)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                at android.os.Looper.loop(Looper.java:135)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5753)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
                                                                             Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.MapFragment.getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)' on a null object reference
                                                                                at com.zuercher.zuerchertechnik.Display_contact.onCreate(Display_contact.java:41)
                                                                                at android.app.Activity.performCreate(Activity.java:6112)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1117)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2609)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2721) 
                                                                                at android.app.ActivityThread.access$900(ActivityThread.java:168) 
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                at android.os.Looper.loop(Looper.java:135) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5753) 
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200) 
  </code></pre>