我正在我的应用中集成 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");
最佳答案
它已通过以下方式修复:
- 对 Google Play 服务使用相同版本 (3.1.0)
- 将所有依赖旧版本 Google Play 服务的库更新为最新版本,在我的例子中,OneSignal 库已更新至最新版本
关于android - Firebase getInstance 总是抛出无虚拟方法异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46040855/