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 trialJie Ding
4,839 PointsWhy 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
4,839 PointsOK 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.
@Override
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);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
ParseObject message = mMessages.get(position);
if (message.getString(ParseConstants.KEY_FILE_TYPE).equals(ParseConstants.TYPE_IMAGE)) {
holder.iconImageView.setImageResource(R.drawable.ic_action_picture);
}
else {
holder.iconImageView.setImageResource(R.drawable.ic_action_play_over_video);
}
holder.nameLabel.setText(message.getString(ParseConstants.KEY_SENDER_NAME));
return rowView;
}