2014-01-28 68 views
0

我在Android應用程序中添加了GoogleMap v2。在正常使用中,我沒有問題。 但是,如果我重置手機並安裝我的應用程序,地圖崩潰。谷歌地圖v2崩潰,如果首次使用Android

報告:

Caused by: java.lang.NullPointerException: CameraUpdateFactory is not initialized 

當我更新谷歌的服務,這個bug消失。

任何人都會有一個軌跡,或強制用戶在使用應用程序之前更新Google服務的方法?

感謝

例外:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.app/com.test.app.activity.AcHome}: java.lang.NullPointerException: CameraUpdateFactory is not initialized 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2067) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092) 
    at android.app.ActivityThread.access$600(ActivityThread.java:133) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:137) 
    at android.app.ActivityThread.main(ActivityThread.java:4794) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 
    at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.NullPointerException: CameraUpdateFactory is not initialized 
    at com.google.android.gms.internal.s.b(Unknown Source) 
    at com.google.android.gms.maps.CameraUpdateFactory.aX(Unknown Source) 
    at com.google.android.gms.maps.CameraUpdateFactory.newLatLngZoom(Unknown Source) 
    at com.test.app.activity.AcHome.onCreate(AcHome.java:126) 
    at android.app.Activity.performCreate(Activity.java:5008) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2031) 
    ... 11 more 
+0

發佈您的所有logcat。 –

+0

和你的代碼... –

+0

你可以看看我的幫手庫在github上:https://github.com/yayaa/MapHelper – yahya

回答

1

您可以啓動您的地圖活動如果用戶有谷歌的更新版本播放服務,或者至少你需要一個前檢查。

public static int isGooglePlayServicesAvailable (Context context)

驗證谷歌播放服務的安裝和該 設備上啓用,而此設備上安裝的版本是年齡不超過 該客戶端所需要的一個。

返回指示是否有錯誤的狀態碼。在ConnectionResult中可以是以下一個 :SUCCESS,SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED,SERVICE_DISABLED,SERVICE_INVALID, DATE_INVALID。

如果您這樣做'檢查'並收到'update_required',那麼您可以將用戶重定向到該更新。

檢查鏈接: https://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesUtil.html#isGooglePlayServicesAvailable(android.content.Context)

這是你在找什麼?

+0

這是正確的,謝謝:) – MissGalet