Incompatible types: object cannot be converted to ParseObject

I have a group with my application using Parse. To populate the LitsView with parse objects, I used the following adapter class. The problem is I am getting the error

ParseObject statusObject = mStatus.get(position);

      

Error: Error: (44, 47) error: Incompatible types: Object could not be converted to ParseObject

What's going on here?

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

import com.parse.ParseObject;

import java.util.List;

public class StatusAdapter extends ArrayAdapter {
protected Context mContext;
protected List mStatus;

public StatusAdapter(Context context, List status) {
    super(context, R.layout.homepage, status);
    mContext = context;
    mStatus = status;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder;

    if (convertView == null) {
        convertView = LayoutInflater.from(mContext).inflate(
                R.layout.homepage, null);
        holder = new ViewHolder();
        holder.usernameHomepage = (TextView) convertView
                .findViewById(R.id.usernameHP);
        holder.statusHomepage = (TextView) convertView
                .findViewById(R.id.statusHP);

        convertView.setTag(holder);
    } else {

        holder = (ViewHolder) convertView.getTag();

    }

    ParseObject statusObject = mStatus.get(position);

    // title
    String username = statusObject.getString("user");
    holder.usernameHomepage.setText(username);

    // content
    String status = statusObject.getString("newStatus");
    holder.statusHomepage.setText(status);

    return convertView;
}

public static class ViewHolder {
    TextView usernameHomepage;
    TextView statusHomepage;

}

}

      

+3


source to share


1 answer


You are not using a generic list ( List<E>

). Either you have to throw the object:

ParseObject statusObject = (ParseObject) mStatus.get(position);

or use a list like: protected List<ParseObject> mStatus;



Then you don't need to cast it. You will also need to change the constructor:

public StatusAdapter(Context context, List<ParseObject> status) {
    super(context, R.layout.homepage, status);
    mContext = context;
    mStatus = status;
}

      

0


source







All Articles