我收到此异常:
android.content.res.Resources$NotFoundException: String resource ID #0x0
异常堆栈跟踪指向适配器类中的此行:
holder.no_of_sems.setText(cgpa.getNo_of_sems());
这是我的适配器类:
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); } } }
这是我的POJO课:
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; } }
您不小心调用了TextView.setText带有int资源ID 的版本。
TextView.setText
int
您应该将其显式转换为String:
String
holder.no_of_sems.setText(Integer.toString(cgpa.getNo_of_sems()));