0

I trying to get the length of my array when parsing json using retrofit, but it return error android.content.res.Resources$NotFoundException: String resource ID #0x1

here is my code. JobBrowseAdapter.java

public class JobBrowseAdapter extends RecyclerView.Adapter<JobBrowseAdapter.MyViewHolder> {

private List<Job> jobList;
private Context mContext;
private String id;

public JobBrowseAdapter(Context mContext, List<Job> jobs) {
    this.mContext = mContext;
    this.jobList = jobs;
}

@Override
public MyViewHolder onCreateViewHolder( ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_project, viewGroup, false);
    return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
    Job job = jobList.get(i);
    myViewHolder.title.setText(job.getTitle());
    myViewHolder.skills.setText("Skills: " + job.getSkills());
    myViewHolder.budget.setText(job.getBudget());
    myViewHolder.bid.setText(job.getBid().size());

    myViewHolder.parentLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Job job = jobList.get(i);
            Toast.makeText(mContext, myViewHolder.title.getText(), Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(mContext, DetailsProjectActivity.class);
            intent.putExtra("idProject", job.getId());
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
            Toast.makeText(mContext, "Tes nih id nya: " + job.getId(), Toast.LENGTH_SHORT).show();
        }
    });
}

@Override
public int getItemCount() {
    return jobList.size();
}

public class MyViewHolder extends RecyclerView.ViewHolder {
    private TextView title;
    private TextView skills;
    private TextView budget;
    private TextView bid;
    private LinearLayout parentLayout;

    private MyViewHolder(@NonNull View itemView) {
        super(itemView);
        title = (TextView)itemView.findViewById(R.id.tvTitleJob);
        skills = (TextView)itemView.findViewById(R.id.tvSkillsJob);
        budget = (TextView)itemView.findViewById(R.id.tvBudgetJob);
        bid = (TextView)itemView.findViewById(R.id.tvBid_Project);
        parentLayout = (LinearLayout)itemView.findViewById(R.id.parent_browse_project_layout);
    }
}

}

i've get the error at myViewHolder.bid.setText(job.getBid().size());. i also tried to use myViewHolder.bid.setText(jobList().size()); but it still give me same error. how to fix this?

imam kusuma
  • 61
  • 1
  • 8

2 Answers2

0

Use myViewHolder.bid.setText(String.valueOf(job.getBid().size())); You are trying to set non String value to setText() method so that this is happening

Rasel
  • 5,488
  • 3
  • 30
  • 39
0

instead of doing

myViewHolder.bid.setText(job.getBid().size());

do this

myViewHolder.bid.setText(String.valueOf(job.getBid().size()));

Calling setText() with an integer value to a textview will make it find a string with that resource id that is being passed. In your code you are passing the size of the list in setText() and it's not able to find the resource string with that id in generated R.string class.

Matthijs
  • 2,483
  • 5
  • 22
  • 33