SoManyGoblins
SoManyGoblins

Reputation: 5927

Image showing on emulator but not on Android tablet

I am developing an Android app which gets an image encoded in base 64 from a web service, and shows it in an ImageView.

My problem is that the image is showing correctly on the emulator, but when running on the tablet (tablet ASUS Transformer with Android 4) the ImageView seems to disappear when loading it with the image.

This is the code I am using to load the ImageView:

ImageView imageView = (ImageView) this.findViewById(R.id.floor_map_view);
Bitmap image = BitmapFactory.decodeByteArray(result, 0, result.length);
imageView.setImageBitmap(image);

The image is obtained correctly from the web service, as I said it is loading correctly on the emulator and plus I've compared the base 64 string received to that sent from my web service and they match.

This is my activity layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="#ffffff">


            <ImageView
                android:contentDescription="floorMapView"
                android:id="@+id/floor_map_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent" 
                android:src="#222222"
                />



</LinearLayout>

Any ideas what might be happening?

Thank you.

edit: using inSampleSize in an BitmapFactory.Options object and using it in the decodeByteArray call makes the image appear, but, as expected, smaller than it should be.

Upvotes: 1

Views: 2199

Answers (3)

Trimikha Valentius
Trimikha Valentius

Reputation: 196

add this line on your AndroidManifest.xml file

   <uses-permission  android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Upvotes: 0

SoManyGoblins
SoManyGoblins

Reputation: 5927

Apparently this is a memory issue, solved it with a low inSample value. It is not ideal, but at least it works for now. Strange out of memory issue while loading an image to a Bitmap object Disappointing, and I thought iOS handling of images was bad.

Upvotes: 1

Chris Bye
Chris Bye

Reputation: 1048

The first thing i would do is to use the debugger to inspect the run-time values of imageView and image in both the debugger and emulator, to see if they differ. If they do, dive deeper into the call stack to see why not, it could be that a resource isn't in the same place in one environment, or any of a number of causes.

If it turns out that the image is being loaded into the activity, use HierarchyViewer to inspect the layout elements of the activity, and see what happened to the missing view (if it is even missing at all).

Upvotes: 0

Related Questions