Error Resources $ NotFoundException: String resource ID # 0x1 Android

2

I have a program that loads data in RecyclerView but gives me an error in:

holder.curso.setText(alumno.getCurso())

getCurso() returns an int. This is the method where I get the error. I tried to cast a string, but nothing.

This is the error that gives me:

  

Resources $ NotFoundException: String resource ID # 0x1 Android

this is my code:

public class AlumnosAdapter extends RecyclerView.Adapter<AlumnosAdapter.AlumnosViewHolder>{
    List<Alumno> listaAlumnos;

    public AlumnosAdapter(List<Alumno> alumnos){
        this.listaAlumnos = alumnos;
    }

    @Override
    public AlumnosViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.vista_recycler, parent, false);
        AlumnosViewHolder holder = new AlumnosViewHolder(v);
        return holder;
    }

        @Override
        public void onBindViewHolder(AlumnosViewHolder holder, int position) {
            Alumno alumno = listaAlumnos.get(position);
            holder.nombreapll.setText(alumno.getNombre() + " " +alumno.getApellidos());
            holder.area.setText(alumno.getArea());
            holder.curso.setText(String.valueOf(alumno.getCurso()));
            try{
                URL imageUrl = new URL(alumno.getFoto_perfil());
                HttpURLConnection con = (HttpURLConnection) imageUrl.openConnection();
                con.connect();
                Bitmap imagen = BitmapFactory.decodeStream(con.getInputStream());
                holder.fotoPerfil.setImageBitmap(imagen);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

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

        public static class AlumnosViewHolder extends RecyclerView.ViewHolder{
            TextView nombreapll;
            TextView area;
            TextView curso;
            ImageView fotoPerfil;
            public AlumnosViewHolder(View itemView) {
                super(itemView);
                nombreapll = (TextView) itemView.findViewById(R.id.textViewNombre);
                area = (TextView) itemView.findViewById(R.id.textViewArea);
                curso = (TextView) itemView.findViewById(R.id.textViewCurso);
                fotoPerfil = (ImageView) itemView.findViewById(R.id.imageViewFotoPerfil);
            }
        }
    }
    
asked by PacoPepe 02.05.2018 в 16:43
source

1 answer

0

You must convert the value that you define alumno.getCurso() , to String :

holder.curso.setText(alumno.getCurso());

since what is happening is that it tries to find a resource with the id that you define, the method setText ( ) can also accept a resource id as a parameter:

You must change to this form by converting the value to String so that you do not try to find a resource in the project and simply add the text within the view:

holder.curso.setText(String.valueOf(alumno.getCurso()));
    
answered by 02.05.2018 в 16:45