public class RoomViewAdapter extends ArrayAdapter<Room> {
private ArrayList<Room> rooms;
private Context context;
private int resource;
public RoomViewAdapter(Context context, int resource, ArrayList<Room> rooms){
super(context, resource, rooms);
this.rooms = rooms;
this.context = context;
this.resource = resource;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
System.out.println(rooms.get(position));
Room room = getItem(position);
String name = room.getName();
Integer count = room.getRoomTasks().size();
LayoutInflater inflater = LayoutInflater.from(context);
convertView = inflater.inflate(resource, parent, false);
TextView txtName = convertView.findViewById(R.id.txtRoomName);
TextView txtCount = convertView.findViewById(R.id.txtRoomTasks);
txtName.setText(name);
if(count == 1){
txtCount.setText(count + " Aufgabe");
}else{
txtCount.setText(count + " Aufgaben");
}
return convertView;
}
}
Dieser Code gibt den Fehler:
java.lang.ClassCastException: java.util.HashMap cannot be cast to de.riemerjonas.homeassistant.haushalt.Room
at de.riemerjonas.homeassistant.adapter.RoomViewAdapter.getView(RoomViewAdapter.java:39)
Es handelt sich also um "Room room = getItem(position);" Wieso bekomm ich eine CastException? Ich habe hier doch gar keine HashMap?