I am trying to implement a GoogleMap object into my code. When I use getMapASync() and assign the map created in the onMapReady() call back to the GoogleMap object I want to use, it works within that method, but once I refer to it outside of that method it says that it is still null. Why? public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
GoogleMap mMap;
private static final int ERROR_DIALOG_REQUEST = 9001;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(servicesOK()) {
        setContentView(R.layout.activity_map);
        if (initMap()) {
            Toast.makeText(this, "Ready to map", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "Map not connected", Toast.LENGTH_SHORT).show();
        }
    }
    else{
        setContentView(R.layout.activity_main);
    }
String mapType2 = Integer.toString(mMap.getMapType());
    Toast.makeText(this, mapType2 + " mMap", Toast.LENGTH_SHORT).show(); 
//This is for debugging purposes
}
public boolean servicesOK(){
    int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if(isAvailable == ConnectionResult.SUCCESS){
        return true;
    }
    else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)){
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable,this,ERROR_DIALOG_REQUEST);
        dialog.show();
    }
    else{
        Toast.makeText(this, "Can't connect to mapping service", Toast.LENGTH_SHORT).show();
    }
    return false;
}
private boolean initMap(){
    if(mMap == null){
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }
    return (mMap != null);
}
@Override
public void onMapReady(GoogleMap map) {
    this.mMap = map;
}
}
The error message I get is this:
FATAL EXCEPTION: main
                                                                         Process: com.ramaya947yahoo.mymaps, PID: 1037
                                                                         java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ramaya947yahoo.mymaps/com.ramaya947yahoo.mymaps.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.google.android.gms.maps.GoogleMap.getMapType()' on a null object reference
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2452)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
                                                                             at android.app.ActivityThread.access$900(ActivityThread.java:155)
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                             at android.os.Looper.loop(Looper.java:152)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5497)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                          Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.google.android.gms.maps.GoogleMap.getMapType()' on a null object reference
                                                                             at com.ramaya947yahoo.mymaps.MainActivity.onCreate(MainActivity.java:34)
                                                                             at android.app.Activity.performCreate(Activity.java:6289)
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2405)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535) 
                                                                             at android.app.ActivityThread.access$900(ActivityThread.java:155) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                             at android.os.Looper.loop(Looper.java:152) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5497) 
                                                                             at java.lang.reflect.Method.invoke(Native Method) 
 
     
    