【问题标题】:Nullpointer on FirebaseRemoteConfig.getInstanceFirebaseRemoteConfig.getInstance 上的空指针
【发布时间】:2016-06-10 13:01:57
【问题描述】:

我通过 MainActivity.onCreate 获取 FirebaseRemoteConfig 实例。 这是简单的 setupCode,但在某些设备上的生产中发生了崩溃。这是堆栈跟踪。我正在使用播放服务 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)

【问题讨论】:

  • com.buscaalimento.android.view.viewcontroller.MainActivity.setupFirebaseRemoteConfig(MainActivity.java:476) 这一行的代码是什么?
  • 我编辑并添加了代码@Shubhank。谢谢
  • 你仍然需要告诉那行代码,因为我不知道你代码中的行号
  • 我添加了行代码的注释。但它是 onCreate setupFirebaseRemoteConfig 内部的调用。
  • Others are seeing this crash 当设备没有安装 Play Services 或者可能是旧版本的 Play Services 时。

标签: android firebase firebase-remote-config


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2020-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      • 2019-07-18
      • 2013-08-12
      相关资源
      最近更新 更多