我正在我的应用程序中集成Firebase实时数据库,我按照添加说明操作,但它总是抛出异常
没有虚拟方法
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)
Project gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
App模块gradle:
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方法中在片段内初始化FireBase数据库:
DatabaseReference mRootRefernce = FirebaseDatabase.getInstance().getReference(); // at this line the exception happened
DatabaseReference reference = mRootRefernce.child("feed");
答案 0 :(得分:2)
由以下内容确定:
答案 1 :(得分:0)
尝试使用最新版本的firebase。
compile 'com.google.firebase:firebase-database:11.2.0'
compile 'com.google.firebase:firebase-core:11.2.0'
谷歌服务:
classpath 'com.google.gms:google-services:3.1.0'
app / build.gradle中的到底有没有?
apply plugin: 'com.google.gms.google-services'