title: how to resolve "java.lang.RuntimeException" error
body: <p>I'm new to android. I built an application in which there is a <code>Button</code> which starts an <code>Activity</code> and there are two more <code>Buttons</code> in that <code>Activity</code> which will open two seperate activities. One of that <code>Activity</code> contains Google map named as nearby search. When I start the nearby search the app is crashing while this <code>Activity</code> was running perfectly before integrating the map. </p>
  
  <p><strong>Here is the log cat</strong></p>
  
  <pre><code>04-02 02:32:40.354: E/AndroidRuntime(22037): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jamaat_times/com.example.jamaattiming.NearbySearch}: java.lang.NullPointerException
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at android.app.ActivityThread.access$600(ActivityThread.java:162)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at android.os.Handler.dispatchMessage(Handler.java:107)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at android.os.Looper.loop(Looper.java:194)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at android.app.ActivityThread.main(ActivityThread.java:5371)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at java.lang.reflect.Method.invoke(Method.java:525)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at dalvik.system.NativeStart.main(Native Method)
  04-02 02:32:40.354: E/AndroidRuntime(22037): Caused by: java.lang.NullPointerException
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at com.example.jamaattiming.NearbySearch.onCreate(NearbySearch.java:36)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at android.app.Activity.performCreate(Activity.java:5122)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
  04-02 02:32:40.354: E/AndroidRuntime(22037):    ... 11 more
  </code></pre>
  
  <p><strong>here is the java file:</strong></p>
  
  <pre><code>    public class NearbySearch extends Activity {
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_nearby_search);
          GoogleMapOptions mapOptions = new GoogleMapOptions();
           GoogleMap maps=(((MapFragment) getFragmentManager().findFragmentById(R.id.map2)).getMap());
  
           mapOptions.mapType(GoogleMap.MAP_TYPE_HYBRID);
           //maps.setMapType(GoogleMap.MAP_TYPE_HYBRID);
           maps.setMyLocationEnabled(true);
           maps.addMarker(new MarkerOptions()
              .position(new LatLng(24.9967 , 66.1234))
              .title("Hello world"));
      }
  
  }
  </code></pre>
  
  <p><strong>here is the xml file:</strong></p>
  
  <pre><code>&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:orientation="vertical" 
      android:background="#808080"&gt;
  
      &lt;fragment
          android:id="@+id/map2"
          android:name="com.google.android.gms.maps.MapFragment"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>and here is the manifest:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.jamaat_times"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
    &lt;uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" /&gt;
  
      &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
      &lt;uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" /&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-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  
  
      &lt;uses-feature
          android:glEsVersion="0x00020000"
          android:required="true" /&gt;
  
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_jamaat"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.example.jamaattiming.Splash"
              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;activity
              android:name="com.example.jamaattiming.MainPage"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.example.CLEARSCREEN" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.example.jamaattiming.Qibla"
              android:label="@string/app_name"
              android:screenOrientation="portrait" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.example.COMPASS" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;activity
              android:name="com.example.jamaattiming.JamaatFinder"
              android:label="@string/title_activity_jamaat_finder" &gt;
          &lt;/activity&gt;
  
          &lt;activity
              android:name="com.example.jamaattiming.QiblaFinder"
              android:label="@string/title_activity_qibla_finder" &gt;
          &lt;/activity&gt;
  
          &lt;activity
              android:name="com.example.jamaattiming.TagYourself"
              android:label="@string/title_activity_tag_yourself" &gt;
          &lt;/activity&gt;
  
          &lt;meta-data
              android:name="com.google.android.maps.v2.API_KEY"
              android:value="my key" /&gt;
          &lt;meta-data
              android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
  
          &lt;activity
              android:name="com.example.jamaattiming.NearbySearch"
              android:label="@string/title_activity_nearby_search" &gt;
          &lt;/activity&gt;
  
  
          &lt;activity
              android:name="com.example.jamaattiming.ManualSearch"
              android:label="@string/title_activity_manual_search" &gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>