Hi there,
I am tryin to run a simple code to illustrate the geolocation service.
Unfortunately I am having an unexpected exception that unable
to execute the activity.
any help!
thank you in advance
------------------------------------ simple pg for geolocalisation
package com.example.lastlocation;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.widget.TextView;
public class MyLocation extends Activity {
TextView tv;
LocationManager mLocationManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.textview1);
mLocationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String locationprovider =
mLocationManager.getBestProvider(criteria, true);
Location mLocation =
mLocationManager.getLastKnownLocation(locationprovider);
String text = "Last location lat: " + mLocation.getLatitude()
+ "long: " + mLocation.getLongitude();
//+ "speed :" + mLocation.getSpeed() +
// "Time: " + mLocation.getTime();
tv.setText(text);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
_________________
----------------------
09-28 22:10:32.784: D/AndroidRuntime(969): Shutting down VM
09-28 22:10:32.784: W/dalvikvm(969): threadid=1: thread exiting with
uncaught exception (group=0x4001d800)
09-28 22:10:32.804: E/AndroidRuntime(969): FATAL EXCEPTION: main
09-28 22:10:32.804: E/AndroidRuntime(969): java.lang.RuntimeException:
Unable to start activity
ComponentInfo{com.example.lastlocation/com.example.lastlocation.MyLocation}:
java.lang.NullPointerException
09-28 22:10:32.804: E/AndroidRuntime(969): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-28 22:10:32.804: E/AndroidRuntime(969): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-28 22:10:32.804: E/AndroidRuntime(969): at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-28 22:10:32.804: E/AndroidRuntime(969): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-28 22:10:32.804: E/AndroidRuntime(969): at
android.os.Handler.dispatchMessage(Handler.java:99)
09-28 22:10:32.804: E/AndroidRuntime(969): at
android.os.Looper.loop(Looper.java:123)
09-28 22:10:32.804: E/AndroidRuntime(969): at
android.app.ActivityThread.main(ActivityThread.java:4627)
09-28 22:10:32.804: E/AndroidRuntime(969): at
java.lang.reflect.Method.invokeNative(Native Method)
09-28 22:10:32.804: E/AndroidRuntime(969): at
java.lang.reflect.Method.invoke(Method.java:521)
09-28 22:10:32.804: E/AndroidRuntime(969): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-28 22:10:32.804: E/AndroidRuntime(969): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-28 22:10:32.804: E/AndroidRuntime(969): at
dalvik.system.NativeStart.main(Native Method)
09-28 22:10:32.804: E/AndroidRuntime(969): Caused by:
java.lang.NullPointerException
09-28 22:10:32.804: E/AndroidRuntime(969): at
com.example.lastlocation.MyLocation.onCreate(MyLocation.java:35)
09-28 22:10:32.804: E/AndroidRuntime(969): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-28 22:10:32.804: E/AndroidRuntime(969): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-28 22:10:32.804: E/AndroidRuntime(969): ... 11 more
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en