Crash in location program
Make application according to the tutorial in the book, but have some error which crashed my program in unknown place: logCat don't gave error message So code of my location class`:
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.TextView;
public class MainActivity extends Activity {
private LocationManager myLocationManager;
private LocationListener myLocationListener;
private TextView myLatitude, myLongitude;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myLatitude = (TextView)findViewById(R.id.textView1);
myLongitude = (TextView)findViewById(R.id.textView2);
myLocationManager = (LocationManager)getSystemService(
Context.LOCATION_SERVICE);
myLocationListener = new MyLocationListener();
myLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
myLocationListener);
//Get the current location in start-up
myLatitude.setText(String.valueOf(
myLocationManager.getLastKnownLocation(
LocationManager.GPS_PROVIDER).getLatitude()));
myLongitude.setText(String.valueOf(
myLocationManager.getLastKnownLocation(
LocationManager.GPS_PROVIDER).getLongitude()));
}
private class MyLocationListener implements LocationListener{
public void onLocationChanged(Location argLocation) {
// TODO Auto-generated method stub
myLatitude.setText(String.valueOf(
argLocation.getLatitude()));
myLongitude.setText(String.valueOf(
argLocation.getLongitude()));
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider,
int status, Bundle extras) {
// TODO Auto-generated method stub
}
};
}
I'm add next permission to MAnifest file: After starting application on my Galaxy TAb i have crash but after few second in a toolbar splashing icon "GPS" code from debuger(if helps)
DalvikVM[localhost:8624]
Thread [<1> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2663
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2679
ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125
ActivityThread$H.handleMessage(Message) line: 2033
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4627
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 868
ZygoteInit.main(String[]) line: 626
NativeStart.main(String[]) line: not available [native method]
Thread [<6> Binder Thread #2] (Running)
Thread [<5> Binder Thread #1] (Running)
Read more
stackoverflow.comm
No comments:
Post a Comment