title: MapView NullPointerException in onCreate
body: <p>I am creating a <code>MapView</code> programmatically like this:</p>
  
  <pre><code>MapView mv = new MapView(this);
  </code></pre>
  
  <p>However this leads to a <code>NullPointerException</code> (see log). If I use another constructor such as</p>
  
  <pre><code>MapView mv = new MapView(this, new GoogleMapOptions());
  </code></pre>
  
  <p>everything is fine. What is the matter?</p>
  
  <p><strong>onCreate:</strong></p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.listings);
  
      mSmallMapView = new MapView(this);
      mSmallMapView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 200));
  
      this.addView(mSmallMapView);
  
      mSmallMapView.onCreate(savedInstanceState);
  }
  </code></pre>
  
  <p><strong>LogCat:</strong></p>
  
  <pre><code>01-19 01:28:20.411: E/AndroidRuntime(16039): FATAL EXCEPTION: main
  01-19 01:28:20.411: E/AndroidRuntime(16039): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.ui.ListingsActivity}: java.lang.NullPointerException
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at android.os.Handler.dispatchMessage(Handler.java:99)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at android.os.Looper.loop(Looper.java:137)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at android.app.ActivityThread.main(ActivityThread.java:5039)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at java.lang.reflect.Method.invokeNative(Native Method)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at java.lang.reflect.Method.invoke(Method.java:511)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at dalvik.system.NativeStart.main(Native Method)
  01-19 01:28:20.411: E/AndroidRuntime(16039): Caused by: java.lang.NullPointerException
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at maps.am.r.a(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at maps.y.ae.a(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at maps.y.bm.onCreate(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.google.android.gms.maps.internal.IMapViewDelegate$Stub.onTransact(IMapViewDelegate.java:66)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at android.os.Binder.transact(Binder.java:310)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.google.android.gms.maps.internal.IMapViewDelegate$a$a.onCreate(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.google.android.gms.maps.MapView$b.onCreate(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.google.android.gms.internal.d$3.a(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.google.android.gms.internal.i.b(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.google.android.gms.maps.MapView$a.a(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.google.android.gms.maps.MapView$a.a(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.google.android.gms.internal.d.a(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.google.android.gms.internal.d.onCreate(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.google.android.gms.maps.MapView.onCreate(Unknown Source)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at com.example.ui.ListingsActivity.onCreate(ListingsActivity.java:108)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at android.app.Activity.performCreate(Activity.java:5104)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
  01-19 01:28:20.411: E/AndroidRuntime(16039):    ... 11 more
  </code></pre>