无法从android中解析来自User类的ParseFile。只有其他课程

时间:2016-01-23 02:57:26

标签: android image parse-platform download

我无法使用下面的代码访问我在Android中解析的用户类中保存的照片。如果我添加一个新类来解析并使用这个确切的代码,它会很好地下载图片。但是,它只是不允许我从解析中的用户类/表中提取。为什么这样,我该如何解决?我需要使用指针吗?如果是这样,怎么样?谢谢。

    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
            "User");


    query.getInBackground("JkANnvy77y",
            new GetCallback<ParseObject>() {

                public void done(ParseObject object,
                                 ParseException e) {
                    // TODO Auto-generated method stub


                    ParseFile fileObject = (ParseFile) object
                            .get("pictest");
                    fileObject
                            .getDataInBackground(new GetDataCallback() {

                                public void done(byte[] data,
                                                 ParseException e) {
                                    if (e == null) {
                                        Log.d("test",
                                                "We've got data in data.");
                                        // Decode the Byte[] into
                                        // Bitmap
                                        Bitmap bmp = BitmapFactory
                                                .decodeByteArray(
                                                        data, 0,
                                                        data.length);

                                        // Get the ImageView from
                                        // main.xml
                                        ImageView image = (ImageView) findViewById(R.id.ImageView6);

                                        // Set the Bitmap into the
                                        // ImageView
                                        image.setImageBitmap(bmp);



                                    } else {
                                        Log.d("test",
                                                "There was a problem downloading the data.");
                                    }
                                }
                            });
                }
            });

更新:我编辑了代码,允许我将parseexception打印到logcat,它告诉我没有找到查询! GRR

1 个答案:

答案 0 :(得分:0)

这是我的另一个项目的代码,使其适应您的需求

  //get all images
    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.findInBackground(new FindCallback<ParseUser>() {
        @Override
        public void done(List<ParseUser> objects, ParseException e) {
            if (objects.size() > 0) {
                if (e == null) {
                    if (!objects.isEmpty()) {
                       //we have grabbed all the users
                      //now lets try to get a file
                    ParseFile file=  (ParseUser)objects.get(0).ParseFile("image");

                    } else if (e.getCode() == ParseException.REQUEST_LIMIT_EXCEEDED) {
                        makeSnack("Error! Reloading images.");

                    } else {
                        e.printStackTrace();
                        Log.v("error", e.getMessage());
                    }
                } else {
                    //TODO:// if not images, reregister loclistener
                    makeSnack("No images located near you.");
                }
            }
        }
    });

}