我正在嘗試使用當前位置使用android谷歌地圖v2.My應用程序正在崩潰...我的代碼和logcat是follow.I搜索了很多以得到它。請刪除它。Android GoogleMapV2當前位置不能正常工作
setContentView(R.layout.location_map);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(bestProvider);
double currentlatitude = location.getLatitude();
double currentlongitude = location.getLongitude();
locationManager.requestLocationUpdates(bestProvider, 20000, 0, this);
CURRENT_LOCATION = new LatLng(currentlatitude, currentlongitude);
我的日誌貓如下
04-24 17:58:33.681: I/x(17640): Making Creator dynamically
04-24 17:58:33.691: W/dalvikvm(17640): Refusing to reopen boot DEX '/system/framework/com.android.location.provider.jar'
04-24 17:58:33.711: I/Google Maps Android API(17640): Google Play services client version: 6587000
04-24 17:58:33.721: I/Google Maps Android API(17640): Google Play services package version: 7329032
04-24 17:58:33.922: D/AbsListView(17640): Get MotionRecognitionManager
04-24 17:58:34.172: I/dalvikvm(17640): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.hg.a
04-24 17:58:34.172: W/dalvikvm(17640): VFY: unable to resolve virtual method 449: Landroid/content/pm/PackageManager;.getPackageInstaller()Landroid/content/pm/PackageInstaller;
04-24 17:58:34.172: D/dalvikvm(17640): VFY: replacing opcode 0x6e at 0x000d
04-24 17:58:34.212: D/AndroidRuntime(17640): Shutting down VM
04-24 17:58:34.212: W/dalvikvm(17640): threadid=1: thread exiting with uncaught exception (group=0x41b53c08)
04-24 17:58:34.222: E/AndroidRuntime(17640): FATAL EXCEPTION: main
04-24 17:58:34.222: E/AndroidRuntime(17640): Process: com.ambilobes.flowbornprivilege, PID: 17640
04-24 17:58:34.222: E/AndroidRuntime(17640): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ambilobes.flowbornprivilege/com.ambilobes.flowbornprivilege.LocationFinder}: java.lang.NullPointerException
04-24 17:58:34.222: E/AndroidRuntime(17640): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
04-24 17:58:34.222: E/AndroidRuntime(17640): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2458)
04-24 17:58:34.222: E/AndroidRuntime(17640): at android.app.ActivityThread.access$900(ActivityThread.java:172)
04-24 17:58:34.222: E/AndroidRuntime(17640): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
04-24 17:58:34.222: E/AndroidRuntime(17640): at android.os.Handler.dispatchMessage(Handler.java:102)
04-24 17:58:34.222: E/AndroidRuntime(17640): at android.os.Looper.loop(Looper.java:146)
04-24 17:58:34.222: E/AndroidRuntime(17640): at android.app.ActivityThread.main(ActivityThread.java:5598)
04-24 17:58:34.222: E/AndroidRuntime(17640): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 17:58:34.222: E/AndroidRuntime(17640): at java.lang.reflect.Method.invoke(Method.java:515)
04-24 17:58:34.222: E/AndroidRuntime(17640): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
04-24 17:58:34.222: E/AndroidRuntime(17640): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
04-24 17:58:34.222: E/AndroidRuntime(17640): at dalvik.system.NativeStart.main(Native Method)
04-24 17:58:34.222: E/AndroidRuntime(17640): Caused by: java.lang.NullPointerException
04-24 17:58:34.222: E/AndroidRuntime(17640): at com.ambilobes.flowbornprivilege.LocationFinder.onCreate(LocationFinder.java:61)
04-24 17:58:34.222: E/AndroidRuntime(17640): at android.app.Activity.performCreate(Activity.java:5459)
04-24 17:58:34.222: E/AndroidRuntime(17640): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
04-24 17:58:34.222: E/AndroidRuntime(17640): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
04-24 17:58:34.222: E/AndroidRuntime(17640): ... 11 more
04-24 18:03:34.285: I/Process(17640): Sending signal. PID: 17640 SIG: 9
04-24 18:03:34.665: E/Qmage(17959): onDecode : QmageDecodeFrame 20140421
如果你的要求是隻找到位置,你不需要使用谷歌地圖v2的 –
@ Jayesh Elamgodi我需要使用mapv2 PLSE告訴我 – Javad
'getLastKnownLocation()'可以很容易地返回'null'。你不檢查'null'並處理這種情況。 – CommonsWare