2015-04-24 58 views
-3

我正在嘗試使用當前位置使用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 
+0

如果你的要求是隻找到位置,你不需要使用谷歌地圖v2的 –

+0

@ Jayesh Elamgodi我需要使用mapv2 PLSE告訴我 – Javad

+0

'getLastKnownLocation()'可以很容易地返回'null'。你不檢查'null'並處理這種情況。 – CommonsWare

回答

0

這顯然無關與谷歌地圖API V2 ...

的RuntimeException:無法啓動活動ComponentInfo {com.ambilobes .flowbornprivilege/com.ambilobes.flowbornprivilege.LocationFinder}:java.lang.NullPointerException

你得到了你自己NullPointerException。讓我們來看看它:

產生的原因:顯示java.lang.NullPointerException

在com.ambilobes.flowbornprivilege.LocationFinder.onCreate(LocationFinder.java:61)

LocationFinder .java:61,你會發現你的問題。

+0

我沒有獲得第61行的當前緯度。您可以在Android上面看到 – Javad

+0

以上的行,我從來沒有說過你。 Logcat說你得到一個例外......你介意發佈代碼嗎?如果你這樣做,你會介意告訴我們哪一行是第61行嗎? – shkschneider

+0

double currentlatitude = location.getLatitude();第61行 – Javad