I am getting this exception:
android.content.res.Resources$NotFoundException: String resource ID #0x0
The exception stack trace points to this line in the adapter class:
holder.no_of_sems.setText(cgpa.getNo_of_sems());
This is my adapter class:
public class adapter_cgpa extends RecyclerView.Adapter<adapter_cgpa.Viewholder> { ArrayList<POJO> cgpaArrayList; public adapter_cgpa(ArrayList<POJO> cgpaArrayList) { this.cgpaArrayList = cgpaArrayList; } @NonNull @Override public adapter_cgpa.Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View listitem = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_cgpa, parent, false); return new Viewholder(listitem); } @Override public void onBindViewHolder(@NonNull adapter_cgpa.Viewholder holder, int position) { POJO cgpa= cgpaArrayList.get(position); holder.no_of_sems.setText(cgpa.getNo_of_sems()); } @Override public int getItemCount() { return cgpaArrayList.size(); } public class Viewholder extends RecyclerView.ViewHolder { TextView cname, no_of_sems, cgpa, percentage,schemec; ImageButton btndelete2; public Viewholder(@NonNull View itemView) { super(itemView); no_of_sems=(TextView)itemView.findViewById(R.id.no_of_sem); } } }
This is my POJO class:
public class POJO { int no_of_sems; public void setNo_of_sems(int no_of_sems) { this.no_of_sems = no_of_sems; } public int getNo_of_sems() { return no_of_sems; } }
Advertisement
Answer
You’re accidentally calling the version of TextView.setText
that takes an int
resource ID.
You should explicitly convert it to a String
:
holder.no_of_sems.setText(Integer.toString(cgpa.getNo_of_sems()));