无法从PopulateViewHolder

时间:2016-12-06 07:00:46

标签: android firebase firebase-realtime-database firebaseui

我有这个

        FirebaseRecyclerAdapter mAdapter = new FirebaseRecyclerAdapter<ChatList, ChatHolder>(ChatList.class, R.layout.chatlistrow, ChatHolder.class, chatRef) {
            @Override
            public void populateViewHolder(ChatHolder chatViewHolder, final ChatList chatList, final int position) {

                //try catch block to catch events of no posts, it will most likely return a null error, so im catching it, else
                //find its exception and catch it

                String fullName = mAdapter.getRef(position).getKey();
                chatViewHolder.setName(fullName);

但该行

String fullName = mAdapter.getRef(position).getKey();

mAdapter需要宣布为最终版。当我宣布它是最终的时,它说,mAdapter从未被初始化。 解决方案,请

1 个答案:

答案 0 :(得分:2)

您正试图访问自己。 mAdapter == this

您可以使用this或省略它:

String fullName = this.getRef(position).getKey();

String fullName = getRef(position).getKey();