java – Android ImageView Is Not Displaying Image?-ThrowExceptions

Exception or error:

Can anyone tell me why the following code is not working? The Image does not appear at all.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"

   <ImageView
          android:src="@drawable/splashscreen"
          android:scaleType="center"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" />

</RelativeLayout>
How to solve:

In my case, all my fragment’s imageViews are not showing when I run my application. The problem is, I extend my “Activity” class from “FragmentActivity“. so I just change it “FragmentActivity” to “AppCompatActivity

maybe this will help someone.

###

Where did you put the source image file? Is that under the Drawable folder? If so, then create mdpi, hdpi, xhdpi, xxhdpi image source for the image, and put them in mdpi, hdpi, xhdpi, xxhdpi folders.

###

This is the solution that worked for me after checking the layout xml, theme etc. Just changing the “extends Activity” from your java class to “extends AppCompatActivity”.

Should some of the previous suggested solutions worked for you, others having the same problem with ImageView image not showing might try this as well.

###

I had the same issue and I fixed it by extending AppCompatActivity and renaming my image to correct standard.
My image name (previously): splash-1 (didn’t worked).
And I tried renaming image name to splash1.
After that everything worked.
note: the image file might also be responsible for this problem.

###

Check for the following:

  1. Are you invoking setContentView (for your splash screen) on the UI thread
  2. Are there other activities (or views) that you’re displaying too quickly after your splash screen (i.e. nullifying the splash screen setContentView)?
  3. Trying using match_parent instead of wrap_content on the ImageView layout_height and layout_width.

###

What format is your drawable file in? Android prefers using .PNG mostly.

###

A null bitmap = unusable image.

This is the basis for how an image is actually used. When an image is used in android and it is assigned it actually converts the image into a bitmap, and depending on certain parameters being size and various other factors, it can fail, which would result in your image being converted and being returned as null due to some failure that occurred.

###

I had this same problem. I really cannot believe how simple it was. Though this may not be the issue for you, this fixed it for me. My image file was named
ss-logo.png. Android Studio does not allow dashes in image files. Once I changed it to ss_logo.png, it worked perfectly. Only use letters, numbers, and underscores in your image file name. Hope this helps.

###

Don’t create drawable folder yourself. Recreate it with Image Asset option in android studio.

In my case, the problem was drawable folder itself. i had created drawable folder myself. it’s not correct. in the android studio we should create drawable folder with Image Asset option. i didn’t get the reason but now the problem is sloved.

###

In my case, the image wasn’t visible while choosing the image from the list of images.

Rebuilding the project fixed it for me.

Build -> Rebuild Project

###

try making the image size a little less, I guess the android studio doesn’t support the image with higher pixels .Anyway it solved my problem

###

Try to check the name of your image
eg:”img-icon-butterfly.png” these type of names should be renamed and “-” should be removed so instead use names like “imgbutterfly.png”

###

Image file name matters as well. Make sure when you name your image, there are no spaces. Use “_” instead or something

###

Try android:background="@drawable/your_image" instead of app:srcCompat="@drawable/your_image"

###

Please check your image color…If you are using the white background and if you use the white color image then it will not be displayed…Try changing your background container for the image to some other color or change your image color. I really faced this situation and wasted lot of time…I hope this will help someone…

###

I copied/pasted a PNG image into the Drawable folder and set all the info and params in XML file

—> image showed in the Preview but not on actually device/emulator.

So–> In Java Activity, I recalled it programmatically:

  ImageView imview = (ImageView) findViewById(R.id.IdFromXML);
    imview.setImageResource(0);
Drawable draw = getResources().getDrawable(R.drawable.NameOfTheFileInFolder);
draw = (draw);
imview.setImageDrawable(draw);

Got it done!

Convert Image to PNG if necessary. Plenty free converters online.

###

I was facing the exact same problem. I tried rebuild but it did not help. Finally I resized the image from its original size of 2400×2400 to 1200×1200 using an online PNG resizer and then compressed it from 590KB to 150KB file size using an online compressor.

###

I was facing the same issue. After a bit of work I found out that if
I placed the image in the drawable(anydpi), which was being rendered in the design preview but not on the real device it was a problem. So, I placed the image inside simple drawable folder rather than drawable(anydpi). That fixed my issue.

###

Android ImageView Is Not Displaying Image?

none of these solutions are not worked for me. what i did was i added these code lines in my manifest file

android:hardwareAccelerated=”false”

android:largeHeap=”true”

if these codes line didn’t solve your problem try to set your image view height and width. not using wrap content or match parent. if your size didn’t worked. try to reduce the number and retry. i think these solutions are helpful.

###

In ImageView there is two options src and srcCompact. Try both of them to find out which is working.

android:src="@drawable/slide_view_4"

and

app:srcCompat="@drawable/slide_view_4"

###

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

###

Many of the image related issues are solved by using the third party libraries like Picasso by Jake Wharton. I had unexplained issues with image loading and some times even getting out of memory error. That was especially cased by imaged edited (using Gimp for Mac). Picasso does the hard work of handling the memory and necessary caching etc.

http://square.github.io/picasso/

Leave a Reply

Your email address will not be published. Required fields are marked *