gpt4 book ai didi

java - 显示图像 - 错误 : incompatible types: ParseObject cannot be converted to ParseFile

转载 作者:行者123 更新时间:2023-12-01 11:58:16 25 4
gpt4 key购买 nike

我想从 Parse 数据库检索并显示文件类型数据 - 照片。在另一个 fragment 中,我使用了下面的方法,显示照片时没有任何问题,因为它是 ParseUser 对象的一列。

现在,我有一个简单的对象,但在运行它之前我的代码中出现以下错误:

Error:(114, 73) error: incompatible types: ParseObject cannot be converted to 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);
}
// ...
}

最佳答案

Error:(114, 73) error: incompatible types: ParseObject cannot be converted to ParseFile

因为shopParseObjectParseQuery而不是ParseFile。所以 shop 的 get 方法返回 ParseObject :

ParseObject prof_obj = (ParseObject)scoreList.get(0);
prof_photo = (ParseFile)prof_obj.get("photo");

关于java - 显示图像 - 错误 : incompatible types: ParseObject cannot be converted to ParseFile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28190913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com