nostra13/Android-Universal-Image-Loader · error · IllegalArgumentException
ImageAware should wrap ImageView. ImageViewAware is expected
Error message
ImageAware should wrap ImageView. ImageViewAware is expected.
What it means
OldRoundedBitmapDisplayer is the sample app's legacy rounded-corner displayer; like the library's RoundedBitmapDisplayer it requires an ImageViewAware target and throws IllegalArgumentException otherwise, because roundCorners() needs the ImageView's dimensions and the result is set via setImageBitmap on the view. It exists in the sample (sample/src/.../ext/) to demonstrate a pre-1.9 displayer implementation.
Source
Thrown at sample/src/main/java/com/nostra13/universalimageloader/sample/ext/OldRoundedBitmapDisplayer.java:53
* <b>NOTE:</b> It's strongly recommended your {@link ImageView} has defined width (<i>layout_width</i>) and height
* (<i>layout_height</i>) .<br />
* <b>NOTE:</b> New {@link Bitmap} object is created for displaying. So this class needs more memory and can cause
* {@link OutOfMemoryError}.
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
*/
public class OldRoundedBitmapDisplayer implements BitmapDisplayer {
private final int roundPixels;
public OldRoundedBitmapDisplayer(int roundPixels) {
this.roundPixels = roundPixels;
}
@Override
public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {
if (!(imageAware instanceof ImageViewAware)) {
throw new IllegalArgumentException("ImageAware should wrap ImageView. ImageViewAware is expected.");
}
Bitmap roundedBitmap = roundCorners(bitmap, (ImageViewAware) imageAware, roundPixels);
imageAware.setImageBitmap(roundedBitmap);
}
/**
* Process incoming {@linkplain Bitmap} to make rounded corners according to target
* {@link com.nostra13.universalimageloader.core.imageaware.ImageViewAware}.<br />
* This method <b>doesn't display</b> result bitmap in {@link ImageView}
*
* @param bitmap Incoming Bitmap to process
* @param imageAware Target {@link com.nostra13.universalimageloader.core.imageaware.ImageAware ImageAware} to
* display bitmap in
* @param roundPixels Rounded pixels of corner
* @return Result bitmap with rounded corners
*/
public static Bitmap roundCorners(Bitmap bitmap, ImageViewAware imageAware, int roundPixels) {
ImageView imageView = imageAware.getWrappedView();View on GitHub (pinned to ba33ec64d0)
Solutions
- Use an ImageViewAware/ImageView target with this displayer
- Replace it with the library's RoundedBitmapDisplayer (same behavior, maintained, supports margin) — while still targeting an ImageView
- For non-view processing, drop the displayer and apply rounding manually on the returned bitmap
Example fix
// before
imageLoader.displayImage(uri, nonViewAware,
new DisplayImageOptions.Builder().displayer(new OldRoundedBitmapDisplayer(16)).build());
// after
imageLoader.displayImage(uri, imageView,
new DisplayImageOptions.Builder().displayer(new RoundedBitmapDisplayer(16)).build()); Defensive patterns
Strategy: type-guard
Validate before calling
if (aware instanceof ImageViewAware) {
imageLoader.displayImage(uri, aware, oldRoundedOptions);
} else {
imageLoader.displayImage(uri, aware, plainOptions);
} Type guard
private static boolean canUseOldRounded(ImageAware aware, DisplayImageOptions opts) {
return !(opts.getDisplayer() instanceof OldRoundedBitmapDisplayer)
|| aware instanceof ImageViewAware;
} Prevention
- Treat sample/ext classes as references, not production dependencies — prefer the library's RoundedBitmapDisplayer
- Apply the same 'displayer implies ImageViewAware' rule to any custom BitmapDisplayer you write
When it happens
Trigger: Applying OldRoundedBitmapDisplayer through DisplayImageOptions while displaying into a NonViewAware or custom ImageAware; copying this sample class into app code and using it with loadImage(uri, targetSize, listener)-style flows that build NonViewAware internally.
Common situations: Copy-pasting sample code into production; keeping pre-1.9 displayer implementations alive after migrating to ImageAware-based APIs; using the sample's 'old rounded corners' option against non-view targets.
Related errors
- ImageAware should wrap ImageView. ImageViewAware is expected
- ImageAware should wrap ImageView. ImageViewAware is expected
- ImageAware should wrap ImageView. ImageViewAware is expected
- displayer can't be null
- Image request failed with response code
AI-assisted analysis of nostra13/Android-Universal-Image-Loader@ba33ec64d0 (2026-08-14).
Data as JSON: /api/errors/9905a57b37fc0e53.
Report an issue: GitHub.