无法解析DatabaseReference

时间:2017-05-12 18:07:09

标签: android firebase android-recyclerview

我正在尝试初始化数据库连接,但每次我在应用程序午餐时都会崩溃

这是错误:

                                                                --------- beginning of crash
                          05-12 20:58:14.279 10772-10772/qu.easycookproject E/AndroidRuntime: FATAL EXCEPTION: main
                                                                Process: qu.easycookproject, PID: 10772
                                                                java.lang.NoSuchMethodError: No virtual method zzUU()Z in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/qu.easycookproject-2/split_lib_dependencies_apk.apk:classes17.dex)
                                                                    at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
                                                                    at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
                                                                    at qu.easycookproject.FireApp.onCreate(FireApp.java:16)
                                                                    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
                                                                    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
                                                                    at android.app.ActivityThread.access$1500(ActivityThread.java:151)
                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                    at android.os.Looper.loop(Looper.java:135)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

这里是mainActivity

 db = FirebaseDatabase.getInstance().getReference().child("cook");
    recyclerView = (RecyclerView) findViewById(R.id.recycleview);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
      FirebaseRecyclerAdapter<Blog , BlogViewHolder> adapter = new FirebaseRecyclerAdapter<Blog, BlogViewHolder>(
       Blog.class,
       R.layout.indivi_row,
       BlogViewHolder.class,
       db

     ) {
   @Override
   protected void populateViewHolder(BlogViewHolder viewHolder, Blog model, int position) {
       viewHolder.setTitle (model.getTitle());
       viewHolder.setDesc (model.getDesc());

   }

};

    recyclerView.setAdapter(adapter);


}

依赖关系:

 compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-database:10.2.0'
compile 'com.google.firebase:firebase-crash:10.2.0'
compile 'com.google.firebase:firebase-auth:10.2.0'
compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.google.firebase:firebase-messaging:10.2.1'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.firebaseui:firebase-ui-database:0.4.0'

和FireApp

   public class FireApp extends Application {
   public void onCreate()
    {
    super.onCreate();
    Firebase.setAndroidContext(this);

    }
   }

如果有人能帮助我解决这个错误,那么我将感激不尽

1 个答案:

答案 0 :(得分:0)

您正在使用旧版SDK和新SDK:

// legacy
Firebase.setAndroidContext(this);

// new
db = FirebaseDatabase.getInstance().getReference().child("cook");

这不是好习惯,可能是问题的根源。

您应该专门使用新的SDK。从构建依赖项中删除此行并更新代码:

compile 'com.firebase:firebase-client-android:2.3.1'

Upgrade Guide很有用。

您还必须对所有Firebase库使用相同的版本。将firebase-messaging更改为10.2.0。

并且还要注意使用与所使用的Firebase库兼容的FirebaseUI版本。对于Firebase libs 10.2.1,请使用FirebaseUI 1.2.0。