3
我正在使用Parse對我的應用程序進行一些分組。爲了用解析對象填充LitsView,我使用了下面的適配器類。問題是,我在不兼容的類型:無法將對象轉換爲ParseObject
ParseObject statusObject = mStatus.get(position);
得到一個錯誤,該錯誤內容如下:錯誤:(44,47)錯誤:不兼容的類型:對象不能轉換到的parseObject
這裏發生了什麼?
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;
}
}
檢查什麼mStatus.get(位置)返回 –
你得到這個問題,因爲'默認返回'Object' GET'方法,所以你要麼把結果或使用'List'的通用版本。請檢查我的答案。 –