FirebaseRemoteConfig.getInstance上的Nullpointer

时间:2016-06-10 13:01:58

标签: android firebase firebase-remote-config

我通过MainActivity.onCreate获取FirebaseRemoteConfig实例。 这是一个简单的setupCode,但在某些设备上生产时会发生崩溃。这是堆栈跟踪。我正在使用playservices 9.0.1。

有什么想法吗?

  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)

2 个答案:

答案 0 :(得分:0)

如果您的依赖项中有不同版本的播放服务或firebase,则会发生此错误。所有版本必须相同,例如:11.6.2

答案 1 :(得分:0)

此外,请检查您的google-services.json是否为最新