Hi i am new to android development. i am trying to get the users coordinates using the GPS, i get the error saying FATAL EXCEPTION: main Android.
here is my code
package lk.adspace.finetech;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class Main extends Activity implements LocationListener {
    TextView viewlocation;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L,1.0f, this);
        boolean isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);
        if (isGPS){
        }else{
            startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
        }
        String locationProvider = LocationManager.GPS_PROVIDER;
        locationManager.requestLocationUpdates(locationProvider, 400, 1, this);
        // Location loc =   locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        Location loc =   locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        viewlocation = (TextView) findViewById(R.id.location);
        viewlocation.setText("My Current location \n Latitude = "+ loc.getLatitude()+" \n Longitude = "+ loc.getLongitude());
    }
    ...
}
This the error i get
08-20 12:08:37.436: E/AndroidRuntime(25888): FATAL EXCEPTION: main
08-20 12:08:37.436: E/AndroidRuntime(25888): java.lang.RuntimeException: Unable to start activity ComponentInfo{lk.adspace.finetech/lk.adspace.finetech.Main}: java.lang.NullPointerException
08-20 12:08:37.436: E/AndroidRuntime(25888):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at android.app.ActivityThread.access$600(ActivityThread.java:162)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at android.os.Handler.dispatchMessage(Handler.java:107)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at android.os.Looper.loop(Looper.java:194)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at android.app.ActivityThread.main(ActivityThread.java:5371)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at java.lang.reflect.Method.invokeNative(Native Method)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at java.lang.reflect.Method.invoke(Method.java:525)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at dalvik.system.NativeStart.main(Native Method)
08-20 12:08:37.436: E/AndroidRuntime(25888): Caused by: java.lang.NullPointerException
08-20 12:08:37.436: E/AndroidRuntime(25888):    at lk.adspace.finetech.Main.onCreate(Main.java:68)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at android.app.Activity.performCreate(Activity.java:5122)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
08-20 12:08:37.436: E/AndroidRuntime(25888):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
08-20 12:08:37.436: E/AndroidRuntime(25888):    ... 11 more
can anyone help me to fix this problem. tnx.
 
     
     
     
    