0
public class DayAdapter extends BaseAdapter {

    private Context mContext;
    private Day[] mDays;

    public DayAdapter(Context context, Day[] days) {
        mContext = context;
        mDays = days;
    }

    @Override
    public int getCount() {
        return mDays.length;
    }

    @Override
    public Object getItem(int i) {
        return mDays[i];
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder holder;

        if(view==null){
            view = LayoutInflater.from(mContext).inflate(R.layout.daily_list_item, null);
            holder = new ViewHolder();
            holder.iconImageView = (ImageView) view.findViewById(R.id.iconImageView);
            holder.dayLabel = (TextView) view.findViewById(R.id.dayNameLabel);
            holder.temperatureLabel = (TextView) view.findViewById(R.id.temperatureLabel);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }
        Day day = mDays[i];
        holder.dayLabel.setText(day.getDayOfTheWeek());

        holder.temperatureLabel.setText(day.getMaxTemperature()+"");
        holder.iconImageView.setImageResource(day.getIconId());

        return view;
    }

    private static class ViewHolder{
        ImageView iconImageView;
        TextView temperatureLabel;
        TextView dayLabel;
    }
}

I get the exception:

FATAL EXCEPTION: main
java.lang.NullPointerException at app.com.example.tmrovsky.czywgdynipada.Adapters.DayAdapter.getView(DayAdapter.java:62)

I don't know where there is an error during setting these three: holder.dayLabel.setText(day.getDayOfTheWeek()); and so on. I tried to debug and there is no null value(it's correctly Tueasday). Any ideas, my brothers? :)

Cheesebaron
  • 21,926
  • 13
  • 60
  • 110
Tomasz Ciunel
  • 1,069
  • 2
  • 8
  • 4
  • Are you sure `day` object is not **NULL** in `getView()`? – user370305 Mar 17 '15 at 21:35
  • 2
    GO to that line in a debugger. Check every possible item that has a . to the right of it (or a [] to the right of it) and make sure it isn't null. One of them is. Work back from there. – Gabe Sechan Mar 17 '15 at 21:37
  • If day and the value you are getting from it are not `null`, then this usually indicates that it can't find the view with that ID in the inflated view. Also don't use that signature for the `inflate` method instead use `inflate(R.layout.daily_list_item, viewGroup, false);`, otherwise you will experience funkyness with sizing of your views at some point. – Cheesebaron Mar 17 '15 at 21:37

0 Answers0