具有单个字符串值的失败绑定程序事务,RecycleView/Firebase



我遇到了一个问题,我试图使用从Firebase Firestore绑定的数据创建RecyclerViewFirestore CollectionReference包含具有单个值的文档"name",但是当我绑定它时,它说FAILED BINDER TRANSACTION并说;

E/Android运行时:致命异常:main 进程: com.example.ashaneen.firebaseapp, PID: 28014 java.lang.StackOverflow错误:堆栈大小 8MB at 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) at android.view.View.rebuildOutline(View.java:12141) at android.view.View.invalidateDrawable(View.java:16796) at 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) at 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)

朋友片段.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;
}
}

朋友模型.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;
}
}

朋友持有人.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);
}
}

我已经找到了解决方案,问题出在

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

应该有getActivity()作为参数而不是getApplicationContext()虽然问题已经解决,但如果有人知道为什么这样工作,我将不胜感激。

相关内容

  • 没有找到相关文章