android - Firebase getInstance 总是抛出无虚拟方法异常

标签 android firebase firebase-realtime-database

我正在我的应用中集成 Firebase 实时数据库,我按照添加说明进行操作,但它总是抛出异常

No virtual method

FATAL EXCEPTION: main
  Process: appsTest.test, PID: 17680
  java.lang.NoSuchMethodError: No virtual method zzcnu()Z in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/appsTest.test-2/base.apk:classes15.dex)
      at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
      at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
      at appsTest.test.inAppViews.newsFeedScreen.NewsFeedFragment.<init>(NewsFeedFragment.java:31)
      at appsTest.test.inAppViews.BaseActivity.onClickOnTab(BaseActivity.java:144)
      at appsTest.test.inAppViews.BaseActivity.onTabSelected(BaseActivity.java:258)
      at com.ashokvarma.bottomnavigation.BottomNavigationBar.sendListenerCall(BottomNavigationBar.java:578)
      at com.ashokvarma.bottomnavigation.BottomNavigationBar.selectTabInternal(BottomNavigationBar.java:558)
      at com.ashokvarma.bottomnavigation.BottomNavigationBar.access$000(BottomNavigationBar.java:44)
      at com.ashokvarma.bottomnavigation.BottomNavigationBar$1.onClick(BottomNavigationBar.java:502)
      at android.view.View.performClick(View.java:6213)
      at android.view.View$PerformClick.run(View.java:23645)
      at android.os.Handler.handleCallback(Handler.java:751)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:154)
      at android.app.ActivityThread.main(ActivityThread.java:6692)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

项目分级

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

应用程序模块等级:

compile "com.google.firebase:firebase-messaging:+"
compile "com.google.firebase:firebase-core:9.6.1"
compile 'com.google.firebase:firebase-database:9.6.1'
apply plugin: 'com.google.gms.google-services' // this code at the end of gradle file

在 OnCreate 方法中初始化 Fragment 内的 FireBase 数据库:

    DatabaseReference mRootRefernce = FirebaseDatabase.getInstance().getReference(); // at this line the exception happened
    DatabaseReference reference = mRootRefernce.child("feed");

最佳答案

它已通过以下方式修复:

  1. 对 Google Play 服务使用相同版本 (3.1.0)
  2. 将所有依赖旧版本 Google Play 服务的库更新为最新版本,在我的例子中,OneSignal 库已更新至最新版本

关于android - Firebase getInstance 总是抛出无虚拟方法异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46040855/

相关文章:

java - 联系 7 "It seems that you device does not support camera"

Android MediaPlayer 错误 (1,-1)?

android - 在 Android 中使用相机手电筒

android - 如何在不使用 ShareActivity 的情况下直接更新 Google+ 状态?

swift - 无法将数据添加到 firebase

ios - 使用observeSingleEvent更新Firebase本地数据

java - 在一个 Firebase 数据库中使用两种不同的结构

javascript - 我需要从 $scope 到其他数据库的不同 id 中获取最大值

json - 类型转换中的 Firebase Swift 3 错误

node.js - nodejs firebase实时数据库排序不起作用