我想从Parse数据库中检索并显示文件类型数据 - 照片。在另一个片段中,我使用了下面的方法,我在显示照片时没有任何问题,它是ParseUser对象的一列。
现在,我有一个简单的对象,但是在我运行它之前,我的代码中出现了以下错误:
错误:(114,73)错误:不兼容的类型:ParseObject不能 转换为ParseFile
错误是指此行:prof_photo = (ParseFile)shop.get("photo");
String name = null;
if (getArguments() != null) {
if (getArguments().getString("name") != null) {
name = getArguments().getString("name");
ParseUser currentUser = ParseUser.getCurrentUser();
final ParseQuery<ParseObject> shop = ParseQuery.getQuery("Shop");
shop.whereEqualTo("name", name);
shop.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
ParseFile prof_photo = null;
try {
prof_photo = (ParseFile)shop.get("photo");
} catch (ParseException e1) {
e1.printStackTrace();
}
if (prof_photo != null) {
prof_photo.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
// data has the bytes for the resume
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
photo.setImageBitmap(bmp);
} else {
// something went wrong
String message = "Something went wrong with displaying the photo!";
Toast.makeText(DisplayShopFragment.this.getActivity().getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
}
});
}
else {
photo.setBackgroundResource(R.drawable.shop);
}
// ...
}
答案 0 :(得分:1)
错误:(114,73)错误:不兼容的类型:ParseObject不能 转换为ParseFile
因为shop
是ParseQuery
的{{1}}而不是ParseObject
。所以获取ParseFile
返回shop
的方法:
ParseObject