error in GPS update location

Rma_80

New member
Oct 27, 2011
0
0
0
Hallo,
i cant run the below app. and i receive the following error:
" the application has stopped unexpectedly, pleasetry again"

Code:
package com.androidbook.GPS_Sensor_Project;

import android.app.Activity;
import android.content.Context;
import android.location.GpsSatellite;
import android.location.GpsStatus;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class GPS_Sensor_ProjectActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        LocationListener locationListener = new MyLocationListener();
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
        
        
    }
    
}
==========================================================================
Code:
package com.androidbook.GPS_Sensor_Project;

import android.content.Context;
import android.content.ContextWrapper;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class MyLocationListener implements LocationListener {

	@Override
	public void onLocationChanged(Location loc) {
		// TODO Auto-generated method stub
        loc.getLatitude();
        loc.getLongitude();
        Context context = null ;
        context.getApplicationContext();
        String text = "current location is: " + "latitude = " +loc.getLatitude() +
        		                                "longitude = " +loc.getLongitude();
        
        /*TextView tv = new TextView(this);
        tv.setText(text);
        setContentView(tv);*/ 
        Toast.makeText(context.getApplicationContext(), "location changed", Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onProviderDisabled(String arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onProviderEnabled(String arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub

	}

}
==========================================================================
 

Trending Posts

Forum statistics

Threads
956,346
Messages
6,967,697
Members
3,163,516
Latest member
KidColoringPage