java - 解析云不返回图像

标签 java android parse-platform

我花了 3 天多的时间从 Parse Cloud 获取图像文件。但它什么也没返回。我已经检查了后端,数据已添加到那里,但它没有返回图像。有天使可以帮我解决这个问题吗?

 // Set up a customized query
        ParseQueryAdapter.QueryFactory<AnywallPost> factory =
                new ParseQueryAdapter.QueryFactory<AnywallPost>() {
                    public ParseQuery<AnywallPost> create() {
                        Location myLoc = (currentLocation == null) ? lastLocation : currentLocation;
                        ParseQuery<AnywallPost> query = AnywallPost.getQuery();
                        query.include("user");
                        query.orderByDescending("createdAt");
                        query.include("image");
                        query.whereWithinKilometers("location", geoPointFromLocation(myLoc), radius
                                * METERS_PER_FEET / METERS_PER_KILOMETER);
                        query.setLimit(MAX_POST_SEARCH_RESULTS);
                        return query;
                    }
                };

        // Set up the query adapter
        postsQueryAdapter = new ParseQueryAdapter<AnywallPost>(this, factory) {
            @Override
            public View getItemView(AnywallPost post, View view, ViewGroup parent) {
                if (view == null) {
                    view = View.inflate(getContext(), R.layout.anywall_post_item, null);
                }
                ParseFile photo = (ParseFile) post.get("image");
                TextView contentView = (TextView) view.findViewById(R.id.content_view);
                image = (ImageView) view.findViewById(R.id.picture_view);
                imageloader.DisplayImage(post.getPhoto(),image);
                TextView usernameView = (TextView) view.findViewById(R.id.username_view);
                contentView.setText(post.getText());
                usernameView.setText(post.getUser().getUsername());
                post.setPhoto(photo.getUrl());
                return view;
            }
        };

编辑版本:

  // Set up a customized query
        ParseQueryAdapter.QueryFactory<AnywallPost> factory =
                new ParseQueryAdapter.QueryFactory<AnywallPost>() {
                    public ParseQuery<AnywallPost> create() {
                        Location myLoc = (currentLocation == null) ? lastLocation : currentLocation;
                        ParseQuery<AnywallPost> query = AnywallPost.getQuery();
                        query.include("user");
                        query.orderByDescending("createdAt");
                        query.whereWithinKilometers("location", geoPointFromLocation(myLoc), radius
                                * METERS_PER_FEET / METERS_PER_KILOMETER);
                        query.setLimit(MAX_POST_SEARCH_RESULTS);
                        return query;
                    }
                };

        // Set up the query adapter
        postsQueryAdapter = new ParseQueryAdapter<AnywallPost>(this, factory) {
            @Override
            public View getItemView(AnywallPost post, View view, ViewGroup parent) {
                if (view == null) {
                    view = View.inflate(getContext(), R.layout.anywall_post_item, null);
                }
                ParseFile photo = (ParseFile) post.get("image");
                if (photo != null) {
                    photo.getDataInBackground(new GetDataCallback() {

                        @Override
                        public void done(byte[] data, ParseException e) {
                            // TODO Auto-generated method stub
                            if (data != null && e == null) {
                                Bitmap bitmap = BitmapFactory
                                        .decodeByteArray(data, 0,
                                                data.length);
                                image.setImageBitmap(bitmap);

                            } else {
                                //ParseException e
                            }
                        }
                    });
                } else {
                    //picture_not_available
                }
                TextView contentView = (TextView) view.findViewById(R.id.content_view);
                image = (ImageView) view.findViewById(R.id.picture_view);
                TextView usernameView = (TextView) view.findViewById(R.id.username_view);
                contentView.setText(post.getText());
                usernameView.setText(post.getUser().getUsername());
                post.setPhoto(photo.getUrl());
                return view;
            }
        };

最佳答案

您必须使用getDataInBackground获取图像资源

if (photo != null) {
                photo.getDataInBackground(new GetDataCallback() {

                    @Override
                    public void done(byte[] data, ParseException e) {
                        // TODO Auto-generated method stub
                        if (data != null && e == null) {
                            Bitmap bitmap = BitmapFactory
                                    .decodeByteArray(data, 0,
                                            data.length);
                            image.setImageBitmap(bitmap);

                        } else {
                            //ParseException e
                        }
                    }
                });
            } else {
                //picture_not_available
            }

关于java - 解析云不返回图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34564117/

相关文章:

java - 替换 Java 中过时的 Hashtable 类

android - 如果一个方法在 onResume() 中运行,那么在 onCreate() 中运行该方法是否会是多余的?

java - 为什么 Java native 缓冲区那么慢?

ios - 我正在尝试按位置对用户的帖子进行排序并使用 PFGeopoint 和 Swift 显示距离

android - 带有解析问题android的facebook登录

java - 并发问题 - 从 Java 多线程服务器下载的同一文件的大小不同

JavaFX:获取动态创建的按钮的ID

JVM HotSpot 上的 Java 异常计数器

android - 如何在 Jetpack Compose 中正确使用 StateFlow?

android - "at least one ID field (installationId,deviceToken) must be specified in this operation"解析