title: How Can I get Longitude and Latitude and put it into JSON link?
body: <p>I've been trying to grab longitude and latitude with LocationListener and casting it as an int to put into a JSON link so I can use the data from current user location. My app crashes when I try to start it but I can get the longitude and latitude coordinates. I've broken my app down to just simply being able to grab the longitude and latitude from one activity and trying to get those values in another activity where I will put my JSON activity. Is there something I'm missing?</p>
  
  <hr>
  
  <p>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="viaan.carl.mytest" &gt;
  
  &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".MainActivity"
          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;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>MAIN ACTIVITY</p>
  
  <pre><code>import android.content.Context;
  import android.location.Criteria;
  import android.location.Location;
  import android.location.LocationListener;
  import android.location.LocationManager;
  import android.os.Bundle;
  import android.app.Activity;
  
  import android.view.Menu;
  
  import android.widget.Toast;
  
  
  public class MainActivity extends Activity implements LocationListener {
  
  LocationManager locationmanager;
  myGPS gps = new myGPS(this);
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      locationmanager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
      Criteria cri=new Criteria();
      String provider=locationmanager.getBestProvider(cri,false);
  
      if(provider!=null &amp; !provider.equals(""))
      {
          Location location=locationmanager.getLastKnownLocation(provider);
          locationmanager.requestLocationUpdates(provider,2000,1,this);
          if(location!=null)
          {
              onLocationChanged(location);
          }
          else{
              Toast.makeText(getApplicationContext(),"location not found",Toast.LENGTH_LONG ).show();
          }
      }
      else
      {
          Toast.makeText(getApplicationContext(),"Provider is null",Toast.LENGTH_LONG).show();
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  @Override
  public void onLocationChanged(Location location) {
  
      int lat;
      gps.setLat((int) location.getLatitude());
      int lng;
      gps.setLng((int) location.getLongitude());
  
      //TextView textView2=(TextView)findViewById(R.id.textview2);
  
      //TextView textView3=(TextView)findViewById(R.id.textview3);
  
      //textView2.setText("Latitude"+location.getLatitude());
      //textView3.setText("Longitude" + location.getLongitude());
  
  }
  @Override
  public void onStatusChanged(String s, int i, Bundle bundle) {
  }
  @Override
  public void onProviderEnabled(String s) {
  }
  @Override
  public void onProviderDisabled(String s) {
  }
  
  }
  </code></pre>
  
  <p>Getter &amp; Setter Class</p>
  
  <pre><code>import android.app.Activity;
  import android.content.SharedPreferences;
  
  public class myGPS {
  
  private int lat;
  private int lng;
  SharedPreferences prefs;
  
  public myGPS(Activity activity) {
      prefs = activity.getPreferences(Activity.MODE_PRIVATE);
  }
  
  
  void setLng(int lng) {
      this.lng = lng;
  }
  
  int getLat() {
      return lat;
  }
  
  int getLng() {
      return lng;
  }
  
  void setLat(int lat) {
      this.lat = lat;
  }
  }
  </code></pre>
  
  <p>New Class where JSON will be (currently just trying to display the data)</p>
  
  <pre><code>import android.location.Location;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  public class LocationDisplay extends Fragment {
  
  TextView textView2;
  TextView textView3;
  
  myGPS gps;
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_wind, container, false);
      textView2 = (TextView)rootView.findViewById(R.id.textview2);
      textView3 = (TextView)rootView.findViewById(R.id.textview3);
  
      return rootView;
  }
  
  public LocationDisplay () {
      textView2.setText("Latitude: " + gps.getLat());
      textView3.setText("Longitude: " + gps.getLng());
  }
  }
  </code></pre>
  
  <p>LogCat</p>
  
  <pre><code>06-05 11:36:52.499    1943-1943/? D/dalvikvm﹕ Late-enabling CheckJNI
  06-05 11:36:52.567    1943-1943/viaan.carl.mytest E/Trace﹕ error opening trace file: No such file or directory (2)
  06-05 11:36:52.575    1943-1943/viaan.carl.mytest D/AndroidRuntime﹕ Shutting down VM
  06-05 11:36:52.575    1943-1943/viaan.carl.mytest W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa619f908)
  06-05 11:36:52.583    1943-1943/viaan.carl.mytest E/AndroidRuntime﹕ FATAL EXCEPTION: main
  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{viaan.carl.mytest/viaan.carl.mytest.MainActivity}: java.lang.NullPointerException
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
          at android.app.ActivityThread.access$600(ActivityThread.java:141)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:137)
          at android.app.ActivityThread.main(ActivityThread.java:5041)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:511)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
          at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.NullPointerException
          at android.content.ContextWrapper.getPackageName(ContextWrapper.java:135)
          at android.app.Activity.getLocalClassName(Activity.java:4415)
          at android.app.Activity.getPreferences(Activity.java:4449)
          at viaan.carl.mytest.myGPS.&lt;init&gt;(myGPS.java:16)
          at viaan.carl.mytest.MainActivity.&lt;init&gt;(MainActivity.java:29)
          at java.lang.Class.newInstanceImpl(Native Method)
          at java.lang.Class.newInstance(Class.java:1319)
          at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  at android.app.ActivityThread.access$600(ActivityThread.java:141)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:137)
  at android.app.ActivityThread.main(ActivityThread.java:5041)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>