小编典典

使用TextView.setText显示数据时出错:Resources $ NotFoundException:字符串资源ID#0x0

java

我收到此异常:

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;
    }
}

阅读 222

收藏
2020-11-01

共1个答案

小编典典

您不小心调用TextView.setText带有int资源ID
的版本

您应该将其显式转换为String

holder.no_of_sems.setText(Integer.toString(cgpa.getNo_of_sems()));
2020-11-01