title: How to Latitude and Longitude in android
body: <p>I have developed simple application to display the latitude and longitude in android... but it is showing the null pointer exception... please let me know what is the error..</p>
  
  <p>My Activity class</p>
  
  <pre><code>import android.app.Activity;
  import android.content.Context;
  import android.location.Location;
  import android.location.LocationListener;
  import android.location.LocationManager;
  import android.os.Bundle;
  import android.widget.Toast;
  
  
  public class SignalStrengthActivity extends Activity implements LocationListener{
  
      private LocationManager  locationManager;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
      }
  
  
      @Override
      protected void onResume() {
          locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, this);
          super.onResume();
      }
  
      @Override
      protected void onPause() {
          locationManager.removeUpdates(this);
          super.onPause();
      }
  
  
      @Override
      public void onLocationChanged(Location location) {
           if (location != null) {
                  Toast.makeText(this, "Latitude and Longitude " + location.getLatitude() + " " + 
                          location.getLongitude(), Toast.LENGTH_SHORT).show();
              }
  
      }
  
      @Override
      public void onProviderDisabled(String provider) {
  
           Toast.makeText(this, "Latitude and Longitude Offline ", Toast.LENGTH_SHORT).show();
      }
  
      @Override
      public void onProviderEnabled(String provider) {
  
  
      }
  
      @Override
      public void onStatusChanged(String provider, int status, Bundle extras) {
  
  
      }
  }
  </code></pre>
  
  <p>My Manifest file :-</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.latitudelongitude"
      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.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.example.latitudelongitude.SignalStrengthActivity"
              android:configChanges="orientation|keyboardHidden|screenSize"
              android:label="@string/app_name"
              android:theme="@style/FullscreenTheme" &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;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>when i execute the application it does not display anything.. indicating that the location object is null... please let me know how to fix the problem</p>