im trying to get int data from firestore but before that app crashes i dont know why when i try it as string it work i get it and i can list it but when i try it int app crashes even before get data here is my code second part is my adapter logchat said 2 line is wrong i mark it with stairs for u
FirebaseFirestore firestore; ArrayList<String> useremaillist; ArrayList<Integer> userpointlist; SkorAdapter skorAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_skor_board); firestore=FirebaseFirestore.getInstance(); useremaillist=new ArrayList<>(); userpointlist=new ArrayList<>(); getscore(); RecyclerView skorboardrecyclerView=findViewById(R.id.recyclerView); skorboardrecyclerView.setLayoutManager(new LinearLayoutManager(this)); skorAdapter=new SkorAdapter(useremaillist,userpointlist); skorboardrecyclerView.setAdapter(skorAdapter); } public void getscore(){ CollectionReference collectionReference=firestore.collection("Kullanıcılar ve Skorlar"); collectionReference.orderBy("skor", Query.Direction.DESCENDING).addSnapshotListener(new EventListener<QuerySnapshot>() { @Override public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) { userpointlist.clear(); useremaillist.clear(); if(error!=null){ Log.e("tag",error.getLocalizedMessage()); } if(value!=null){ for(DocumentSnapshot snapshot:value.getDocuments()){ Map<String,Object> userdatat=snapshot.getData(); String emailt=(String) userdatat.get("email"); int skor=(int) userdatat.get("skor"); useremaillist.add(emailt); userpointlist.add(skor); skorAdapter.notifyDataSetChanged(); } } } }); } ** public class SkorAdapter extends RecyclerView.Adapter<SkorAdapter.Holder> { private ArrayList<String> emaillistforadapter; private ArrayList<Integer> pointlistforadapter; public SkorAdapter(ArrayList<String> emaillistforadapter,ArrayList<Integer> pointlistforadapter ) { this.emaillistforadapter = emaillistforadapter; this.pointlistforadapter = pointlistforadapter; } @NonNull @Override public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { LayoutInflater layoutInflater=LayoutInflater.from(parent.getContext()); View view=layoutInflater.inflate(R.layout.skorboard_row,parent,false); return new Holder(view); } @Override public void onBindViewHolder(@NonNull SkorAdapter.Holder holder, int position) { holder.useremailtext.setText(emaillistforadapter.get(position)); ** holder.userpointtext.setText(pointlistforadapter.get(position)); } @Override public int getItemCount() { return emaillistforadapter.size(); } public class Holder extends RecyclerView.ViewHolder { TextView useremailtext; TextView userpointtext; public Holder(@NonNull View itemView) { super(itemView); useremailtext=itemView.findViewById(R.id.kullanıcımailtext); userpointtext=itemView.findViewById(R.id.kullanıcıpointtext); } }
Advertisement
Answer
The problem is in the adapter then.
You have a private ArrayList<Integer> pointlistforadapter;
and the problem is that you are doing holder.userpointtext.setText(pointlistforadapter.get(position));
and setText()
accepts a CharSeq
and it lets you add an Int
in paramter because it also has this signature :
And since it’s not a resid it crashes.
What you can do is :
holder.userpointtext.setText(pointlistforadapter.get(position).toString());