2016-06-10 34 views
1

我通過MainActivity.onCreate獲取FirebaseRemoteConfig實例。 這是簡單的setupCode,但某些設備上的生產正在發生崩潰。這是堆棧跟蹤。我正在使用playservices 9.0.1。FirebaseRemoteConfig.getInstance上的空指針

有什麼想法?

protected void onCreate(Bundle savedInstanceState) { 

      super.onCreate(savedInstanceState); 
      setupFirebaseRemoteConfig(); //line 476 
    } 


    private void setupFirebaseRemoteConfig() { 

      mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); 

      FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder() 
        .setDeveloperModeEnabled(BuildConfig.DEBUG) 
        .build(); 

      mFirebaseRemoteConfig.setConfigSettings(configSettings); 
      mFirebaseRemoteConfig.setDefaults(R.xml.remote_config); 

      configCacheExpiration = 3600; 

      if (mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) { 
       configCacheExpiration = 0; 
      } 
     } 

    Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{}: 

    java.lang.NullPointerException: Attempt to read from field 'int com.google.android.gms.internal.zzaji$zzc.zzbTG' on a null object reference 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) 
     at android.app.ActivityThread.access$900(ActivityThread.java:172) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:145) 
     at android.app.ActivityThread.main(ActivityThread.java:5832) 
     at java.lang.reflect.Method.invoke(Method.java) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
    Caused by java.lang.NullPointerException: Attempt to read from field 'int com.google.android.gms.internal.zzaji$zzc.zzbTG' on a null object reference 
     at com.google.firebase.remoteconfig.FirebaseRemoteConfig.zza(Unknown Source) 
     at com.google.firebase.remoteconfig.FirebaseRemoteConfig.zzbD(Unknown Source) 
     at com.google.firebase.remoteconfig.FirebaseRemoteConfig.getInstance(Unknown Source) 
     at com.buscaalimento.android.view.viewcontroller.MainActivity.setupFirebaseRemoteConfig(MainActivity.java:476) 
     at com.buscaalimento.android.view.viewcontroller.MainActivity.onCreate(MainActivity.java:455) 
     at android.app.Activity.performCreate(Activity.java:6221) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) 
     at android.app.ActivityThread.access$900(ActivityThread.java:172) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:145) 
     at android.app.ActivityThread.main(ActivityThread.java:5832) 
     at java.lang.reflect.Method.invoke(Method.java) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
+0

的是在這行代碼com.buscaalimento.android.view.viewcontroller.MainActivity。 setupFirebaseRemoteConfig(MainActivity.java:476)? – Shubhank

+0

我編輯並添加了代碼@Shubhank。謝謝 –

+0

你還需要告訴那行代碼,因爲我不知道代碼中的行號碼 – Shubhank

回答

0

當您在依賴關係中擁有不同版本的播放服務或Firebase時,會發生此錯誤。所有版本必須是相同的,例如:11.6.2

0

另外,請檢查您的谷歌,services.json是最新