LizG LizG - 5 months ago 25
Android Question

Retrieving an image from parse.com

With the code i am using, the compiler doesn't make it past the first if statement and returns the message "The object was not found ... ".
I am trying to download an image from parse.com and place it in an imageView. Attached is my code, the schema for parse class and my xml layout. Any help would be appreciated.

final ParseImageView mImage = (ParseImageView) findViewById(R.id.image);

ParseQuery<ParseObject> query = new ParseQuery<>("Appetizers");
query.addAscendingOrder("appetizer");
query.getInBackground("imageFiles", new GetCallback<ParseObject>() {
@Override
public void done(ParseObject object, com.parse.ParseException e) {
if (object == null) {
Log.d("test", "The object was not found...");

} else {
Log.d("test", "Retrieved the object.");
final ParseFile fileObject = (ParseFile) object.get("imageFiles");
fileObject.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
Log.d("test", "We've got data in data.");
// use data for something
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,data.length);
mImage.setImageBitmap(bmp);

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


parse.com

content_appetizer_recipe.xml

design of layout

Answer

In the sending class:

ParseObject po = mAppetizers.get(position); // get position
String ID = po.getObjectId().toString();

Intent intent = new Intent(Appetizer.this, AppetizerRecipe.class);

intent.putExtra("ID", ID);
startActivity(intent);

In the receiver's class:

final ParseImageView mImage = (ParseImageView) findViewById(R.id.image);
String ID = getIntent().getStringExtra("ID");

        ParseQuery<ParseObject> getimage = new ParseQuery<>("Appetizers");
    getimage.addAscendingOrder("appetizer");
    getimage.whereEqualTo("ID", ID);
        Log.d("AppetizerRecipe2", "object: " + ID);
    getimage.getInBackground(ID, new GetCallback<ParseObject>() {
        @Override
        public void done(ParseObject object, ParseException e) {
            if (e == null) {
                Log.v("what is e?", "e = " + e);
                // success
                final ParseFile fileObject = (ParseFile)object.get("imageFiles");
                fileObject.getDataInBackground(new GetDataCallback() {
                    public void done(byte[] data, ParseException e) {
                        if (e == null) {
                            Log.d("test", "We've got data in data.");
                            // use data for something
                            Log.d("test", "Get your image..." + fileObject.getUrl());
                    Picasso.with(getBaseContext()).load(fileObject.getUrl()).placeholder
                            (R.drawable.ic_launcher).into(mImage);

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

            } else {
                // fail
                Log.d("test", "Error Message..." + e.getMessage());
            }
        }
    });