package com.isawabird;

import android.app.Application;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.util.Log;

import com.isawabird.MyLocation.LocationResult;
import com.isawabird.parse.ParseConsts;
import com.isawabird.parse.ParseUtils;
import com.parse.Parse;
import com.parse.ParseGeoPoint;

public class ISawABirdApplication extends Application {

	@Override
	public void onCreate() {
		Parse.initialize(this, ParseConsts.APP_ID, ParseConsts.CLIENT_KEY);
		
		/* Initialize with last known location */ 
		LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
		Location lastKnown = null;
		if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)){
			lastKnown = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
			ParseUtils.location = new ParseGeoPoint(lastKnown.getLatitude(), lastKnown.getLongitude());
		}else if(lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
			lastKnown = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
			ParseUtils.location = new ParseGeoPoint(lastKnown.getLatitude(), lastKnown.getLongitude());
		}
		
		MyLocation myLocation = new MyLocation();
		LocationResult locationResult = new LocationResult(){
		    @Override
		    public void gotLocation(Location location){
		        Log.i(Consts.TAG, "Lat , long are " + location.getLatitude() + " " + location.getLongitude());
		        ParseUtils.location = new ParseGeoPoint(location.getLatitude(), location.getLongitude()); 
		    }
		};
		myLocation.getLocation(this, locationResult);

		super.onCreate();
	}
}

@@ -824,103 +824,8 @@
 R);%0A
-%09%09%09ParseUtils.location = new ParseGeoPoint(lastKnown.getLatitude(), lastKnown.getLongitude());%0A
 %09%09%7De
@@ -962,16 +962,46 @@
 VIDER);%0A
+%09%09%7D%0A%09%09if (lastKnown != null)%7B%0A
 %09%09%09Parse

Fix NPE during location capture