Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Lists and Adapters (2015) Using Parcelable Data Retrieving Parcelable Data

Slava Fleer
Slava Fleer
6,086 Points

I still see the empty list text when pressing 7 days button

I still in searching for my mistakes, but maybe someone have in mind quick solution for checking =) I really would be happy for help.

Any way I tried to post Log.v in DayAdapter.java for debugging and it doesn't work. What wrong about same way that we did in MainActivity ?

public class DayAdapter extends BaseAdapter {

    public static final String TAG = DayAdapter.class.getSimpleName();
    Log.v(TAG,"Reached the point in adapter");

    private Context mContext;
    private Day[] mDays;

I have mistake on v in Log.v . It's saying cannot resolve symbol v.

What I understand right now that my adapter is the problem, cause before it worked with simple list of days of a week worked, and in debugging I do see the Parcel data transferred to new activity.

Slava Fleer
Slava Fleer
6,086 Points

my DayAdapter.java code

package com.slava.whetherapp.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.slava.whetherapp.R;
import com.slava.whetherapp.weather.Day;

/**
 * Created by Slava on 08/03/2015.
 */
public class DayAdapter extends BaseAdapter {

    //public static final String TAG = DayAdapter.class.getSimpleName();
    //Log.v(TAG,"Reached the point in adapter");

    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 position) {
        return mDays[position];
    }

    @Override
    public long getItemId(int position) {
        return 0; // we would not use it. Tag items for easy reference.
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;

        if(convertView == null) {
            // Brand new
            convertView = LayoutInflater.from(mContext).inflate(R.layout.daily_list_item, null);
            holder = new ViewHolder();
            holder.iconImageView = (ImageView) convertView.findViewById(R.id.iconImageView);
            holder.temperatureLabel = (TextView) convertView.findViewById(R.id.temperatureLabel);
            holder.dayLabel = (TextView) convertView.findViewById(R.id.dayNameLabel);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Day day = mDays[position];

        holder.iconImageView.setImageResource(day.getIconId());
        holder.temperatureLabel.setText(day.getTemperatureMax() + "");
        holder.dayLabel.setText(day.getDayOfTheWeek());

        return convertView;
    }

    private static class ViewHolder {
        ImageView iconImageView; // public by default
        TextView temperatureLabel;
        TextView dayLabel;
    }
}
Slava Fleer
Slava Fleer
6,086 Points

Something new that I just found about Logs, it must be in method - didn't know about it. I'm going to debug each centimeter of the code with logs right now...

Slava Fleer
Slava Fleer
6,086 Points

my DailyForecastActivity code is running the DayAdapter, at least the constructor. I tried to check the implemented methods in DayAdapter, but it is not show me Log in it. So its not running. What I must check next ? I can't continue the course right now =(

Thanks again for any help.

package com.slava.whetherapp.ui;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;

import com.slava.whetherapp.R;
import com.slava.whetherapp.adapters.DayAdapter;
import com.slava.whetherapp.weather.Day;

import java.util.Arrays;

public class DailyForecastActivity extends ListActivity {

    private Day[] mDays;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_daily_forecast);

        Intent intent = getIntent();
        Parcelable[] parcelables = intent.getParcelableArrayExtra(MainActivity.DAILY_FORECAST);
        mDays = Arrays.copyOf(parcelables, parcelables.length, Day[].class);

        DayAdapter adapter = new DayAdapter(this, mDays);
    }
}

6 Answers

Adam Sommer
Adam Sommer
62,470 Points

Not 100% sure, but I think you have to move the Log.v call into a method. Maybe try moving the Log.v call into the getView() method? Might also try Log.i or Log.d and see if that gives you some output.

Slava Fleer
Slava Fleer
6,086 Points

thanks. yes. you are right with a log. It must be in method. Unfortunately logs didn't help me with my main problem =(

Adam Sommer
Adam Sommer
62,470 Points

Oh right, in the DailyForecastActivity onCreate() method after setting the adapter are you applying it to the activity with

this.setAdapter(adapter);

Might give that a try and see if it populates the ListView. I think that's your main problem right?

Slava Fleer
Slava Fleer
6,086 Points

Yes. I just found it myself. In the video there is no any moment that returning this line =) Thank you. And Ben, you need to add in teacher notes something about it =)

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Glad you got past the Log trouble! Are you still having any other trouble?

Stephen Little
Stephen Little
8,312 Points

Did this get updated or did I just miss it when I went through it?

Angel Viera
Angel Viera
3,293 Points

This was also happening to me. They must have accidentally cut the part where Ben added the call to "setListAdapter(adapter)" at the end of the onCreate() method of DailyForecastActivity. It eventually appears in the video, but they never actually show him write it, so it's easy to miss.

This is what the onCreate method should look like:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_daily_forecast);

        Intent intent = getIntent();
        Parcelable[] parcelables = intent.getParcelableArrayExtra(MainActivity.DAILY_FORECAST);
        mDays = Arrays.copyOf(parcelables, parcelables.length, Day[].class);

        DayAdapter adapter = new DayAdapter(this, mDays);
        setListAdapter(adapter); // <-- THIS LINE
    }
Ben Jakuben
Ben Jakuben
Treehouse Teacher

Doh! Great catch. I'm so sorry about that! I didn't catch that mistake while reviewing this course. I'll make sure we update the video!

Ben Jakuben Hey Ben, the video still is't updated. Just an FYI.

Ben Jakuben Please add it to teachers note

YES! One more vote for a teachers note for this line missing...

Greg Austin
Greg Austin
10,890 Points

Glad it wasn't just me lol. Looked through my code and Android Studio was telling me my "Variable 'adapter' is never used" (you know, the grayed out text and when you hover over it...). Thought, Hey, now, if the adapter is never used that would certainly be the issue here. Took a closer look at the code on the video and sure enough there was the set method. Checked my notes, no mention, checked the vids, no mention. Finally checked the forums just to make sure I wasn't crazy lol.

Just thought I'd share a good tip: go through your variables and such to make sure everything you need has been set and Android Studio makes this real easy by graying out unused variables. Proud of myself for catching that so quickly :)

taubin
taubin
8,705 Points

Unfortunately, this still hasn't been corrected or added to the teachers notes. Luckily I was able to find it here, but it's pretty buried now. Any chance of this being updated?