Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Self-Destructing Message Android App Retrieving and Viewing Messages Creating a Custom List Adapter for Messages

message.getString(ParseConstants.KEY_FILE_TYPE) give null pointer exception. anything in that parameter = null

ParseObject message = mMessages.get(position);

    Log.d(TAG,"this is what get string gets: "+ message.getString("ParseConstants.KEY_FILE_TYPE"));
    //if(message.getString(ParseConstants.KEY_FILE_TYPE).equals(ParseConstants.TYPE_VIDEO)) {
    //else{ //if its a video
     //   holder.iconImageView.setImageResource(R.mipmap.ic_action_play_over_video);

    return convertView;

private static class ViewHolder{
    ImageView iconImageView;
    TextView nameLabel;


like stated in the title, whatever key i use. the value of message.getString is null . I have gone so far as to copy ben's code from every file but the mainActivity file and it still gives me null..... has anyone come across this issue? could it be an issue with Parse.com? To clarify, my cloud has 5 items under the fileType key which are 3 images and 2 videos

I just observed this issue also. It seems the view holder becomes null after initialized once.

1 Answer

Found the bug.

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

    ViewHolder holder = new ViewHolder();

    if (convertView == null) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.message_item, null);
        holder.iconImageView = (ImageView) convertView.findViewById(R.id.messageIcon);
        holder.nameLabel = (TextView) convertView.findViewById(R.id.senderLabel);
        //set holder as tag
    } else{
        holder = (ViewHolder)convertView.getTag();


In the 'else' condition, the line: holder = (ViewHolder)convertView.getTag();

in the above line , calling "convertView.getTag()" without previously calling the corresponding "setTag()" in the 'if' condition.

Adding "convertView.setTag(holder);" after calling "convertView.findViewById(R.id.senderLabel);" in the 'if' condition should do the trick.