У меня возникла проблема с повторным запуском повторного просмотра, и я получаю это раздражающее исключение NullPointerException, независимо от того, что я могу сказать, кто-нибудь, пожалуйста, помогите мне?
это код:
public class AircraftAdapter extends RecyclerView.Adapter<AircraftAdapter.AircraftViewHolder> {
private ArrayList<Aircraft> aircraftList;
public AircraftAdapter(ArrayList<Aircraft> aircraftList) {
this.aircraftList = aircraftList;
}
@NonNull
@Override
public AircraftViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.aircraft_single_cell, parent, false);
return new AircraftViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull AircraftViewHolder holder, int position) {
holder.fill(aircraftList.get(position));
switch (aircraftList.get(position).getStatus()) {
case AT_WORK:
holder.tvAircraftName.setTextColor(Color.GREEN);
break;
case NOT_AT_WORK:
holder.tvAircraftName.setTextColor(Color.RED);
break;
case UNKNOWN:
holder.tvAircraftName.setTextColor(Color.BLACK);
break;
default:
holder.tvAircraftName.setTextColor(Color.GRAY);
}
}
@Override
public int getItemCount() {
return aircraftList.size();
}
public static class AircraftViewHolder extends RecyclerView.ViewHolder {
TextView tvAircraftName , tvAircraftModel;
public AircraftViewHolder(@NonNull View itemView) {
super(itemView);
tvAircraftName = itemView.findViewById(R.id.tv_ac_name);
tvAircraftModel = itemView.findViewById(R.id.tv_ac_model);
}
public void fill(Aircraft aircraft) {
tvAircraftName.setText(aircraft.getName());
tvAircraftModel.setText(aircraft.getModel());
}
}
}
и проблема, которую он мне говорит:
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
at com.example.iai4me.adapters.AircraftAdapter.getItemCount(AircraftAdapter.java:57)
спасибо за помощь :). ........... ............ ............ ............ ... .........