Displaying an image - Error: incompatible types: ParseObject cannot be converted to ParseFile

Displaying an image - Error: incompatible types: ParseObject cannot be converted to ParseFile

我想从 Parse 数据库中检索并显示文件类型数据 - 照片。在另一个片段中,我使用了以下方法,显示照片时没有任何问题,因为它是 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 return ParseObject 的方法:

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