Firebase中从未使用过onCancelled方法

Firebase中从未使用过onCancelled方法

本文介绍了Firebase中从未使用过onCancelled方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在数据库上发送查询,以显示关联的节点号(如果它与用户输入的字符串"token"匹配).但是,我得到的是方法不会从其超类中覆盖方法",而仅为onCancelled函数提供方法中的onCancelled从未在方法中使用".我要去哪里错了?

I'm trying to send a query on database to display the associated node number if it matches with the string 'token' inputed by the user. However, I'm getting a 'Method does not override method from its superclass' and 'Method onCancelled is never used in method' just for the onCancelled function. Where am I going wrong?

        buttonSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Creating firebase object
            Firebase ref = new Firebase(Config.FIREBASE_URL);

            //Getting values to store
            String token = editToken.getText().toString().trim();

            Query query = ref.orderByChild("token").equalTo(token, "token");
            query.addChildEventListener(new ChildEventListener() {



                @Override
                public void onChildAdded(DataSnapshot snapshot, String previousChildKey) {
                    Person user = snapshot.getValue(Person.class);

                    String demo=user.getNodes();

                    System.out.println("Nodes: " + demo);
                }

                @Override
                public void onChildRemoved(DataSnapshot dataSnapshot) {
                    Person friend = dataSnapshot.getValue(Person.class);
                    Toast.makeText(enter_page.this
                            , "Friend removed: " + dataSnapshot.getKey()
                                    + "  token: " + friend.getToken()
                                    + "  name: " + friend.getNodes()
                            , Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                    Person friend = dataSnapshot.getValue(Person.class);
                    Toast.makeText(enter_page.this
                            , "Friend changed: " + dataSnapshot.getKey()
                                    + "  token: " + friend.getToken()
                                    + "  nodes: " + friend.getNodes()
                            , Toast.LENGTH_SHORT).show();
                }
                @Override
                public void onChildMoved(DataSnapshot dataSnapshot, String s) {

                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                    System.out.println("DATABASE ERROR");
                }

            });

推荐答案

OnCanceled 使用FirebaseError而不是DatabaseError,因此应该像这样:

OnCanceled uses a FirebaseError and not a DatabaseError so it should be like this :

 @Override
 public void onCancelled(FirebaseError databaseError) {

     System.out.println("DATABASE ERROR");
 }

重写方法时,参数类型很重要.

Parameters types are important when overriding a method.

这篇关于Firebase中从未使用过onCancelled方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:50