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 Build a Self-Destructing Message Android App Retrieving and Viewing Messages Creating a Custom List Adapter for Messages

Jie Ding
Jie Ding
4,839 Points

Why my Ribbit could not be launched after adding the custom MessageAdapter?

My code is exactly the same as in the lecture of "Creating a custom list adapter for messages", but it goes to error. From the logcat, the error comes from the NullPointerException from the getView() method in the MessageAdapter class. I still do not know why. Can anyone help me? I really appreciate your help!

1 Answer

Jie Ding
Jie Ding
4,839 Points

OK I have solved the issue. I modified the getView() methods provided in the lecture to the following code. Hope it will help someone with similar problems.

    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = convertView;

        if (rowView == null) {
            rowView = LayoutInflater.from(mContext).inflate(R.layout.message_item, null);
            ViewHolder viewHolder = new ViewHolder();
            viewHolder.iconImageView = (ImageView) rowView.findViewById(R.id.message_icon);
            viewHolder.nameLabel = (TextView) rowView.findViewById(R.id.sender_label);

        ViewHolder holder = (ViewHolder) rowView.getTag(); 

        ParseObject message = mMessages.get(position);

        if (message.getString(ParseConstants.KEY_FILE_TYPE).equals(ParseConstants.TYPE_IMAGE)) {
        else {

        return rowView;