具有单个字符串值的失败的BINDER TRANSACTION,RecycleView / Firebase

时间:2018-01-08 15:47:33

标签: android firebase android-recyclerview google-cloud-firestore

我遇到了一个问题,我正在尝试使用RecyclerView绑定的数据创建Firebase FirestoreFirestore CollectionReference包含单值"name"的文档,但是当我绑定它时,它说FAILED BINDER TRANSACTION并说;

  

E / AndroidRuntime:致命异常:主要                                                                                     过程:com.example.ashaneen.firebaseapp,PID:28014                                                                                     java.lang.StackOverflowError:堆栈大小为8MB                                                                                         在android.graphics.Outline.setRoundRect(Outline.java:175)                                                                                         在   android.graphics.drawable.GradientDrawable.getOutline(GradientDrawable.java:1524)                                                                                         在   android.graphics.drawable.InsetDrawable.getOutline(InsetDrawable.java:241)                                                                                         在   android.graphics.drawable.RippleDrawable.getOutline(RippleDrawable.java:680)                                                                                         在   android.view.ViewOutlineProvider $ 1.getOutline(ViewOutlineProvider.java:38)                                                                                         在android.view.View.rebuildOutline(View.java:12141)                                                                                         在android.view.View.invalidateDrawable(View.java:16796)                                                                                         在android.widget.TextView.invalidateDrawable(TextView.java:5405)                                                                                         在   android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:385)                                                                                         在   android.graphics.drawable.RippleDrawable.invalidateSelf(RippleDrawable.java:711)                                                                                         在   android.graphics.drawable.RippleDrawable.cancelExitingRipples(RippleDrawable.java:239)                                                                                         在   android.graphics.drawable.RippleDrawable.jumpToCurrentState(RippleDrawable.java:223)                                                                                         在android.view.View.jumpDrawablesToCurrentState(View.java:17168)                                                                                         在   android.widget.TextView.jumpDrawablesToCurrentState(TextView.java:5339)                                                                                         在   android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6321)                                                                                                                                                                             在01-08 16:25:39.472 28014-28014 / com.example.ashaneen.firebaseapp   E / JavaBinder:!!!失败的粘合剂交易! (包裹大小=   19834640)

FriendsFragment.class

public class FriendsFragment extends Fragment{

    private static final String TAG = "FriendsFragment";

    public FriendsFragment() {
    }

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    CollectionReference friends = FirebaseFirestore.getInstance().collection("Users").document(user.getUid()).collection("friends");

    RecyclerView recyclerView;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_friends,container);

        Log.d(TAG, "onCreateView: "+ friends);
        final Query query = friends.limit(2);
        recyclerView = view.findViewById(R.id.id_recycleViewFriends);
        recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));

        FirestoreRecyclerOptions<FriendModel> options = new FirestoreRecyclerOptions.Builder<FriendModel>()
                .setQuery(query,FriendModel.class)
                .setLifecycleOwner(this)
                .build();

        FirestoreRecyclerAdapter<FriendModel,FriendHolder> adapter = new FirestoreRecyclerAdapter<FriendModel, FriendHolder>(options) {
            @Override
            protected void onBindViewHolder(FriendHolder holder, int position, FriendModel model) {
                   holder.setName(model.getName());
            }

            @Override
            public FriendHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                return new FriendHolder(LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.single_friend_row_test,parent,false));
            }
        };
        recyclerView.setAdapter(adapter);
        return view;
    }
}

FriendModel.class

public class FriendModel
     {
        private String name;


        public FriendModel() {
        }


        public FriendModel(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

    }

FriendHolder.class

public class FriendHolder extends RecyclerView.ViewHolder {

    private TextView name;

    public FriendHolder(View itemView) {
        super(itemView);
        name = itemView.findViewById(R.id.id_name);
    }

    public void setName(String sName) {
      name.setText(sName);
    }

}

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,问题在于

recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));

应该{​​{1}}作为参数而不是getActivity() 虽然问题已经解决,但如果有人知道为什么会这样运作,我将非常感激。