Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Sending Messages Adding a File to the Message: Part 2

Failed to downsize?

I can't display the image from inbox to another view activity: in the video, it's ViewImageActivity. I checked by debugging and log to turn out that the Uri variable right before Picasso method to display image from web gets correct URI. And also, I downloaded the image from Parse database and it was 2560*1920, which seems why it is not displayed(somthing about bitmap being too large).

I think i'm doing downsizing as the video shows, but there must be some lack of code in this following part.

This is the part where the file I try to send is supposed to be downsized.

```byte[] fileBytes = FileHelper.getByteArrayFromFile(this, mMediaUri);

    if (fileBytes == null) {
        return null;
    else {
        if (mFileType.equals(ParseConstants.TYPE_IMAGE)) {
            fileBytes = FileHelper.reduceImageForUpload(fileBytes);
        String fileName = FileHelper.getFileName(this, mMediaUri, mFileType);
        ParseFile file = new ParseFile(fileName, fileBytes);
        message.put(ParseConstants.KEY_FILE, file);

2 Answers

Ben Jakuben
Ben Jakuben
Treehouse Teacher

I just came across your comment in another post. I'm copying my answer here:

I think you need to resize the image even further for certain devices. Each device has a size limit for images that can be viewed in an ImageView. In FileHelper.java, try a smaller size for this variable:

public static final int SHORT_SIDE_TARGET = 1280;

Maybe start testing at 1024?

Timothy Boland
Timothy Boland
18,237 Points

Ive downsized it to 1000...but Im not seeing any images

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Consolidating this comment thread over here. :)

I realized that I, without awareness, deleted "java.io.ByteArrayOutputStream" import within ImageResizer.java by "organize imports" and I thought it was the cause, even though this import is not used within this file, which is why I could delete. But it turned out it does not have anything to do with it.

As a result, the problem disappeared all of a sudden.

Following may not contribute to your experience or this forum, but I'll explain just so you know.

I got the thought deleting this unused import was somehow the problem, because I could successfully store the image with the Brand-new Ribbit app that I built watching videos again very carefully and the only difference between the old one and new one seemed to be this import. But now, when I compared the difference between "with the unused import" and "without the import" in order to conclude that's the bad boy, in both case I succeeded. What surprised me was that I succeeded even with the old app, which I did not change a thing after I had the problem. The problem banished into the thin air like "Time solved the problem", which is never supposed to happen with this I-do-precisely-whatever-you-order-to-do computer thing.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Interesting! I must not have organized my imports with that file. Seems like it's safe to delete.

Sadly, it happens a decent amount of time with Android development (and programming in general) that problems will disappear without a good reason. Usually I chalk it up to having the wrong version on my device or emulator somehow. When I'm having trouble with something that looks like it should work, I'll uninstall the app and restart the emulator and Eclipse, clean the project, and try again with a "fresh" install of the app. Then at least I know I'm 100% using the version of the app I'm currently working on in Eclipse.