我已将此代码放在onCreate类中。
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
String uri = "geo:" + latitude + "," + longitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
this.startActivity(intent);
当应用程序打开时,生病得到不幸,应用已停止。 在logcat中得到错误:
01-17 05:42:08.734: D/AndroidRuntime(1659): Shutting down VM
01-17 05:42:08.734: W/dalvikvm(1659): threadid=1: thread exiting with uncaught exception (group=0x41465700)
01-17 05:42:08.744: E/AndroidRuntime(1659): FATAL EXCEPTION: main
01-17 05:42:08.744: E/AndroidRuntime(1659): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.farugh.neshaniha/com.solidos.neshaniha.FullscreenActivity}: java.lang.NullPointerException
01-17 05:42:08.744: E/AndroidRuntime(1659): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-17 05:42:08.744: E/AndroidRuntime(1659): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-17 05:42:08.744: E/AndroidRuntime(1659): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-17 05:42:08.744: E/AndroidRuntime(1659): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-17 05:42:08.744: E/AndroidRuntime(1659): at android.os.Handler.dispatchMessage(Handler.java:99)
01-17 05:42:08.744: E/AndroidRuntime(1659): at android.os.Looper.loop(Looper.java:137)
01-17 05:42:08.744: E/AndroidRuntime(1659): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-17 05:42:08.744: E/AndroidRuntime(1659): at java.lang.reflect.Method.invokeNative(Native Method)
01-17 05:42:08.744: E/AndroidRuntime(1659): at java.lang.reflect.Method.invoke(Method.java:525)
01-17 05:42:08.744: E/AndroidRuntime(1659): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-17 05:42:08.744: E/AndroidRuntime(1659): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-17 05:42:08.744: E/AndroidRuntime(1659): at dalvik.system.NativeStart.main(Native Method)
01-17 05:42:08.744: E/AndroidRuntime(1659): Caused by: java.lang.NullPointerException
01-17 05:42:08.744: E/AndroidRuntime(1659): at com.solidos.neshaniha.FullscreenActivity.onCreate(FullscreenActivity.java:36)
01-17 05:42:08.744: E/AndroidRuntime(1659): at android.app.Activity.performCreate(Activity.java:5133)
01-17 05:42:08.744: E/AndroidRuntime(1659): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-17 05:42:08.744: E/AndroidRuntime(1659): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-17 05:42:08.744: E/AndroidRuntime(1659): ... 11 more
这怎么可能?
亲切的问候, 马文