Errors for my second Activity  when press button next to open it with the code 
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6169339/android-gps-error-on-mobile-when-button-click">Android gps error on mobile when  button click </a>  </p>
</blockquote>



<pre><code>enter code here
05-31 00:26:46.295: ERROR/AndroidRuntime(4111):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
   05-31 00:32:08.465: ERROR/AndroidRuntime(4301): FATAL EXCEPTION: main
   05-31 00:32:08.465: ERROR/AndroidRuntime(4301): java.lang.RuntimeException: Unable to start activity ComponentInfo{yaraby.y/yaraby.y.yarab}: java.lang.NullPointerException
   05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
  05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at android.app.ActivityThread.access$2300(ActivityThread.java:126)
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at android.os.Handler.dispatchMessage(Handler.java:99)
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at android.os.Looper.loop(Looper.java:123)
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at android.app.ActivityThread.main(ActivityThread.java:4633)
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at java.lang.reflect.Method.invokeNative(Native Method)
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at java.lang.reflect.Method.invoke(Method.java:521)
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
  05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at dalvik.system.NativeStart.main(Native Method)
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301): Caused by: java.lang.NullPointerException
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at yaraby.y.yarab.onCreate(yarab.java:92)
  05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301):     ... 11 more
</code></pre>

<p>Error for such code  this first Activity</p>

<pre><code>enter code here
 public class yaraby extends Activity {
/** Called when the activity is first created. */
String sentence,sentence1, modifiedSentence;;
EditText inputfld, txt;
TextView Text;
Button Enter, Connect, next;
Socket clientSocket;

DataOutputStream outToServer;
BufferedReader inFromServer ;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    inputfld=(EditText)findViewById(R.id.input);
    Text=(TextView)findViewById(R.id.view);
    Enter=(Button)findViewById(R.id.enter);
    Connect=(Button)findViewById(R.id.connect);

    Text.append( "\n about to create a socket");    


    txt=(EditText)findViewById(R.id.txt);
    next = (Button) findViewById(R.id.Button01);   

    next.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try{
            Intent i = new Intent(yaraby.this, yarab.class);
            startActivity(i);
            }
            catch(Error e){
                Log.e("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", e.getMessage());
            }
</code></pre>

<p>}</p>

<pre><code>public void appendText(View view){
    Text.append( "\n  In chat ");

    try{


    sentence=inputfld.getText().toString();
    sentence1="ingyyyy";
    Text.append( "\n  DataStream creating");        
    outToServer.writeBytes(sentence);
    outToServer.writeBytes(sentence1);
    Thread.sleep(1000);
    modifiedSentence = inFromServer.readLine(); 
    Text.append(modifiedSentence);
    inputfld.setText(null);

    }
    catch(Exception modifiedsentence){
        Text.append("Exception");
    }


}


public void connect(View view){
    try{
        clientSocket= new Socket("192.168.1.3",54616); 
        Text.append( "\n created a socket");
        outToServer = new DataOutputStream(clientSocket.getOutputStream());
        Text.append( "\n created a datastream");
        inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        Text.append( "\n created a bufferReader");
        outToServer = new DataOutputStream(clientSocket.getOutputStream());



    }catch(Exception e){
        System.out.println("Error");
    }
}
</code></pre>

<p>Code for the second activity</p>

<pre><code>enter code here
 package yaraby.y;



public class yarab extends MapActivity

{
    Socket clientSocket;
    TextView Text;
    private MapView mapView;
    private MapController mc;
    DataOutputStream outToServer;
    BufferedReader inFromServer ;
         Button start;

    int error = 50;
    GeoPoint p, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,p26,p27,p28,p29;
    List&lt;Overlay&gt; mapOverlays;
    Drawable drawable, drawable2, drawable3, drawable4, drawable6, drawable7,
            drawable8, drawable9, drawable10, drawable11, drawable12,
            drawable13, drawable5, drawable14, drawable15, drawable16, drawable17, drawable18, drawable19, drawable20, drawable21, drawable22, drawable23, drawable24, drawable25, drawable26, drawable27, drawable28, drawable29;
    HelloItemizedOverlay itemizedOverlay, itemizedOverlay2, itemizedOverlay3,
            itemizedOverlay4, itemizedOverlay5, itemizedOverlay6,
            itemizedOverlay7, itemizedOverlay8, itemizedOverlay9,
            itemizedOverlay10, itemizedOverlay11, itemizedOverlay12,
            itemizedOverlay13, itemizedOverlay14, itemizedOverlay15, itemizedOverlay16, itemizedOverlay17, itemizedOverlay18, itemizedOverlay19, itemizedOverlay20, itemizedOverlay21, itemizedOverlay22, itemizedOverlay23, itemizedOverlay24, itemizedOverlay25, itemizedOverlay26, itemizedOverlay27, itemizedOverlay28, itemizedOverlay29;
    LocationManager locationManager;
Button next;
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState)

    {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.main2);

            /* Use the LocationManager class to obtain GPS locations */

            LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

            LocationListener mlocListener = new MyLocationListener();

            mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                    0, mlocListener);
            mapView = (MapView) findViewById(R.id.mapView);

            // enable Street view by default
            mapView.setStreetView(true);

            // enable to show Satellite view
            mapView.setSatellite(true);

            // enable to show Traffic on map
            // mapView.setTraffic(true);
            mapView.setBuiltInZoomControls(true);

            mc = mapView.getController();
            // mapView.setStreetView(true);
            // mapView.setSatellite(true);
            mc.setZoom(12);
            start=(Button)findViewById(R.id.start);

        start.setOnClickListener(new OnClickListener() {

                    @Override
            public void onClick(View v) {
                String j="SSSShoho";
                try {
                    outToServer.writeBytes(j);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                }});
                    }

            //addOverLays();}








    // /lat2=29.98763859272003;
    // log2 = 31.44235074520111
    public void addOverLays() {
        String[] coordinates = { "31.216487288475037", "29.932637214660645",
                "30.084123015403748", "51.5002", "-0.1262",
                "31.337149143218994" };
        double lat = 29.98739718380868, lat2 = 29.987810254096985, lat3 = 29.987574219703674, lat4 = 29.98718498160553, lat5 = 29.98716115951538, lat6 = 29.987241625785828,lat7= 29.98763859272003,lat8=29.9851870536842,lat9=29.987795260925;
        double log = 31.442527770886084, log2 = 31.44258677959442, log3 = 31.44225418567575, log4 = 31.442527770996094, log5 = 31.442500948905945, log6 = 31.44260823726654,log7=31.44251167742004,log8=31.44262969493866,log9=31.44258677959442;
 double t1=((lat3+lat5))/2;
 double t2=((t1+lat3))/2;
 double t3=((t2+lat3))/2;
 double t4=((t3+lat3))/2;
 double t5=((t1+t2))/2;
 double t6=((lat5+t1))/2;
 double t7=((lat3+lat5))/2;
 double t8=((t7+lat3))/2;  
 double t9=((t8+lat3))/2;
 double t10 =((lat2+lat3))/2;
 double t11 =((t7+lat6))/2;
// 29.98763859272003      31.44235074520111
        p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
        p2 = new GeoPoint((int) (lat2 * 1E6 ), (int) (log2 * 1E6 ));
        p3 = new GeoPoint((int) (lat3 * 1e6), (int) (log3 * 1e6));
        p4 = new GeoPoint((int) (lat4 * 1e6), (int) (log4 * 1e6));
        p5 = new GeoPoint((int) (t7* 1e6), (int) (log2 * 1e6));
        p6 = new GeoPoint((int) (lat8 * 1e6), (int) (log8 * 1e6));
        p7 = new GeoPoint((int) (t1* 1e6), (int) (log5 * 1e6));
        p8 = new GeoPoint((int) (lat5 * 1e6), (int) (log5 * 1e6));
        p9 = new GeoPoint((int) (lat6 * 1e6), (int) (log6 * 1e6));
        p10=new GeoPoint( (int) (t4 * 1e6), (int) (log5 * 1e6));
        p11=new GeoPoint( (int) (t2* 1e6), (int) (log5 * 1e6));
        p12=new GeoPoint( (int) (t3* 1e6), (int) (log5 * 1e6));
        p13=new GeoPoint( (int) (t5* 1e6), (int) (log5 * 1e6));
        p14=new GeoPoint( (int) (t6* 1e6), (int) (log5 * 1e6));
        p15=new GeoPoint( (int) ((t6+t1)/2* 1e6), (int) (log3 * 1e6));
        p15=new GeoPoint( (int) (t8* 1e6), (int) (log3 * 1e6));
        p16=new GeoPoint( (int) (t9* 1e6), (int) (log3 * 1e6));
        p17=new GeoPoint( (int) (t10* 1e6), (int) (log3 * 1e6));
        p18=new GeoPoint( (int) (lat9* 1e6), (int) (log9 * 1e6));
        mapOverlays = mapView.getOverlays();
        drawable = this.getResources().getDrawable(R.drawable.wit);
        drawable2 = this.getResources().getDrawable(R.drawable.ballon);
        drawable3 = this.getResources().getDrawable(R.drawable.blackaaaaa);
        drawable4 = this.getResources().getDrawable(R.drawable.wit );
        drawable5 = this.getResources().getDrawable(R.drawable.mar);
        drawable6 = this.getResources().getDrawable(R.drawable.wit);
        drawable7 = this.getResources().getDrawable(R.drawable.wit);
        drawable8 = this.getResources().getDrawable(R.drawable.ggg);
        drawable10= this.getResources().getDrawable(R.drawable.wit);
        drawable9 = this.getResources().getDrawable(R.drawable.pipk);
         drawable11 = this.getResources().getDrawable(R.drawable.wit);
         drawable12 = this.getResources().getDrawable(R.drawable.wit);
         drawable13 = this.getResources().getDrawable(R.drawable.wit);
         drawable14 = this.getResources().getDrawable(R.drawable.wit);
         drawable15 = this.getResources().getDrawable(R.drawable.wit);
         drawable16 = this.getResources().getDrawable(R.drawable.wit);
         drawable17 = this.getResources().getDrawable(R.drawable.wit);
         drawable18 = this.getResources().getDrawable(R.drawable.ggg);
            itemizedOverlay17 = new HelloItemizedOverlay(drawable17, this);
            itemizedOverlay15 = new HelloItemizedOverlay(drawable15, this);
            itemizedOverlay16 = new HelloItemizedOverlay(drawable16, this);
        itemizedOverlay = new HelloItemizedOverlay(drawable, this);
        itemizedOverlay2 = new HelloItemizedOverlay(drawable2, this);
        itemizedOverlay3 = new HelloItemizedOverlay(drawable3, this);
        itemizedOverlay4 = new HelloItemizedOverlay(drawable4, this);
        itemizedOverlay5 = new HelloItemizedOverlay(drawable5, this);
        itemizedOverlay6 = new HelloItemizedOverlay(drawable6, this);
        itemizedOverlay7 = new HelloItemizedOverlay(drawable7, this);
        itemizedOverlay8 = new HelloItemizedOverlay(drawable8, this);
        itemizedOverlay9 = new HelloItemizedOverlay(drawable9, this);
         itemizedOverlay10 = new HelloItemizedOverlay(drawable10,this);
         itemizedOverlay11 = new HelloItemizedOverlay(drawable11,this);
         itemizedOverlay12 = new HelloItemizedOverlay(drawable12,this);
         itemizedOverlay13 = new HelloItemizedOverlay(drawable13,this);
         itemizedOverlay14 = new HelloItemizedOverlay(drawable14,this);
         itemizedOverlay18 = new HelloItemizedOverlay(drawable18,this);
        OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
        OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
        OverlayItem over3 = new OverlayItem(p3, "offff", "over3");
        OverlayItem over4 = new OverlayItem(p4, "offff", "over4");
        OverlayItem over5 = new OverlayItem(p5, "offff", "over5");
        OverlayItem over6 = new OverlayItem(p6, "offff", "over6");
        OverlayItem over7 = new OverlayItem(p7, "offff", "over7");
        OverlayItem over8 = new OverlayItem(p8, "offff", "over8");
        OverlayItem over9 = new OverlayItem(p9, "offff", "over9");
        OverlayItem over10 = new OverlayItem(p10, "offff", "over10");
        OverlayItem over11 = new OverlayItem(p11, "offff", "over11");
        OverlayItem over12 = new OverlayItem(p12, "offff", "over12");
        OverlayItem over13 = new OverlayItem(p13, "offff", "over13");
        OverlayItem over14 = new OverlayItem(p14, "offff", "over14");
        OverlayItem over15 = new OverlayItem(p15, "offff", "over15");
        OverlayItem over16 = new OverlayItem(p16, "offff", "over16");
        OverlayItem over17 = new OverlayItem(p17, "offff", "over17");
        OverlayItem over18 = new OverlayItem(p18, "offff", "over18");
        itemizedOverlay.addOverlay(overlayitem);

        mapOverlays.add(itemizedOverlay);

        itemizedOverlay2.addOverlay(over2);
        mapOverlays.add(itemizedOverlay2);

        itemizedOverlay3.addOverlay(over3);
        mapOverlays.add(itemizedOverlay3);

        itemizedOverlay4.addOverlay(over4);
        mapOverlays.add(itemizedOverlay4);

        itemizedOverlay5.addOverlay(over5);
        mapOverlays.add(itemizedOverlay5);

        itemizedOverlay6.addOverlay(over6);
        mapOverlays.add(itemizedOverlay6);

        itemizedOverlay7.addOverlay(over7);
        mapOverlays.add(itemizedOverlay7);

        itemizedOverlay8.addOverlay(over8);
        mapOverlays.add(itemizedOverlay8);
        itemizedOverlay9.addOverlay(over9);
        mapOverlays.add(itemizedOverlay9);
        itemizedOverlay10.addOverlay(over10);
        mapOverlays.add(itemizedOverlay10);
        itemizedOverlay11.addOverlay(over11);
        mapOverlays.add(itemizedOverlay11);
        itemizedOverlay12.addOverlay(over12);
        mapOverlays.add(itemizedOverlay12);
        itemizedOverlay13.addOverlay(over13);
        mapOverlays.add(itemizedOverlay13);
        itemizedOverlay14.addOverlay(over14);
        mapOverlays.add(itemizedOverlay14);

        itemizedOverlay15.addOverlay(over15);
        mapOverlays.add(itemizedOverlay15);

        itemizedOverlay16.addOverlay(over16);
        mapOverlays.add(itemizedOverlay16);

        itemizedOverlay17.addOverlay(over17);
        mapOverlays.add(itemizedOverlay17);



        itemizedOverlay18.addOverlay(over18);
        mapOverlays.add(itemizedOverlay18);
        mc.setZoom(17);
        mc.animateTo(p2);

        // 7ewarrrrrrrrrrr el remove
        // mapView.getOverlays().remove(itemizedOverlay2);
        // mapView.invalidate();
    }
    public void Location(){



        LocationManager myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);


        LocationListener mlocListener1 = new MyLocationListener();

        LocationManager mlocManager1 = null;
        mlocManager1.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                0, mlocListener1);
            //  Get the current location in start-up
              GeoPoint initGeoPoint = new GeoPoint((int)(myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
           .getLatitude()*1000000),(int)(myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLongitude()*1000000));
           mc.animateTo(initGeoPoint);
        mc.setZoom(16);

        drawable21 = this.getResources().getDrawable(R.drawable.ggg);
        itemizedOverlay21 = new HelloItemizedOverlay(drawable21,this);
        OverlayItem over21 = new OverlayItem(initGeoPoint, "offff", "over21");

        itemizedOverlay21.addOverlay(over21);
        mapOverlays.add(itemizedOverlay21);
        }

    /* Class My Location Listener */

    public class MyLocationListener implements LocationListener

    {

        @Override
        public void onLocationChanged(Location loc)

        {

            GeoPoint point = new GeoPoint((int) (loc.getLatitude() * 1E6),
                    (int) (loc.getLongitude() * 1E6));



            String Text = "My current location is: " +

            "Latitud =" + loc.getLatitude()+ 

            "Longitud =" +loc.getLongitude() ;// loc.getLongitude() ; //loc.getLatitude()+"anoog" + (p3.getLatitudeE6() - error)

            Toast.makeText(getApplicationContext(),

            Text,

            Toast.LENGTH_SHORT).show();
            try {
                outToServer.writeBytes(Text);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

mc.animateTo(point);
</code></pre>

<p>//              if ((p3.getLatitudeE6() - error)&lt;= (loc.getLatitude() * 1E6) &amp;&amp; (loc.getLatitude() * 1E6)&lt;= (p3.getLatitudeE6() + error)) {
        //          mapView.getOverlays().remove(itemizedOverlay3);
            //      mapView.invalidate();</p>

<pre><code>            //}

            // /////////////if (point ==p){
            // /////////////mapView.getOverlays().remove(p);
            // //////////////// }
            // mapView.getOverlays().remove(p);
        }


        private Resources getResources() {
            // TODO Auto-generated method stub
            return null;
        }


        public void onProviderDisabled(String provider)

        {

            Toast.makeText(getApplicationContext(),

            "Gps Disabled",

            Toast.LENGTH_SHORT).show();

        }

        public void onProviderEnabled(String provider)

        {

            Toast.makeText(getApplicationContext(),

            "Gps Enabled",

            Toast.LENGTH_SHORT).show();

        }

        public void onStatusChanged(String provider, int status, Bundle extras)

        {

        }

        protected boolean isRouteDisplayed() {
            return false;
        }

    }/* End of Class MyLocationListener */

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }




                  }
</code></pre>

<p>All i do is i just Press next on first activity to open the map of me !! it didnt Get my Current location </p>
