-3

10-15 17:12:24.365 1102-1102/com.example.nurkan.iip E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException at com.example.nurkan.iip.Adapter.DAdapter.getItemCount(DAdapter.java:61)

public class DAdapter extends RecyclerView.Adapter<DAdapter.RecyclerViewHolder> {


Activity activity;

private List<Dannye> heroes;

public DAdapter(Activity activity, List<Dannye> heroes) {
    this.heroes = heroes;
    this.activity = activity;
}

@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_dannye, parent, false);
    return new RecyclerViewHolder(view);
}

@Override
public void onBindViewHolder(final RecyclerViewHolder holder, int position) {

    final Dannye dannye = heroes.get(position);
    holder.bind(dannye);

}

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


public class RecyclerViewHolder extends RecyclerView.ViewHolder {
    private TextView hour;
    private TextView urok;
    private TextView spes;
    private TextView aut;


    private RecyclerViewHolder(View itemView) {
        super(itemView);
        hour = (TextView) itemView.findViewById(R.id.TWhour);
        urok = (TextView) itemView.findViewById(R.id.TWlesson);
        spes = (TextView) itemView.findViewById(R.id.TWspes);
        aut = (TextView) itemView.findViewById(R.id.TWaut);
    }

    public void bind(Dannye heroModel) {
        hour.setText(heroModel.hour);
        urok.setText(heroModel.lesson);
        spes.setText(heroModel.spes);
        aut.setText(heroModel.aut);
    }
}

}

//проблема в

@Override
public int getItemCount() {
    return heroes.size();
}
C0D3LIC1OU5
  • 8,600
  • 2
  • 37
  • 47
Nurkan
  • 13
  • 1
  • 2
    I believe the error is not in this code... Don´t you have a method named getItemCount at your adapter? Check the line 61 - the nullpointer is there I think. com.example.nurkan.iip.Adapter.DAdapter.getItemCount(DAdapter.java:61) – Curious Mind Oct 15 '18 at 17:05
  • 3
    На этом сайте мы пишем только на английском – Vega Oct 15 '18 at 17:16
  • Please post the exact code at line 61 in your `DAdapter.java` file – C0D3LIC1OU5 Oct 15 '18 at 17:40
  • @Override public int getItemCount() { return heroes.size(); } – Nurkan Oct 15 '18 at 17:49
  • @Nurkan `heroes` is null – Ayush Gupta Oct 15 '18 at 17:51
  • @Nurkan You removed the code you posted earlier where you initialize your array (read form dist and serialize). Your problem is there. Post that code as well so we can help you. – C0D3LIC1OU5 Oct 15 '18 at 18:05

1 Answers1

-2

Your heroes array is null. The code you are using to instantiate isn't working correctly.

C0D3LIC1OU5
  • 8,600
  • 2
  • 37
  • 47