{"record":{"id":"0744054c121cade3","repo":"nostra13/Android-Universal-Image-Loader","slug":"wrong-arguments-were-passed-to-displayimage-meth","errorCode":null,"errorMessage":"Wrong arguments were passed to displayImage() method (ImageView reference must not be null)","messagePattern":"Wrong arguments were passed to displayImage\\(\\) method \\(ImageView reference must not be null\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/core/ImageLoader.java","lineNumber":238,"sourceCode":"\t *                         decoding and displaying. If <b>null</b> - default display image options\n\t *                         {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions)\n\t *                         from configuration} will be used.\n\t * @param targetSize       {@linkplain ImageSize} Image target size. If <b>null</b> - size will depend on the view\n\t * @param listener         {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires\n\t *                         events on UI thread if this method is called on UI thread.\n\t * @param progressListener {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener\n\t *                         Listener} for image loading progress. Listener fires events on UI thread if this method\n\t *                         is called on UI thread. Caching on disk should be enabled in\n\t *                         {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions options} to make\n\t *                         this listener work.\n\t * @throws IllegalStateException    if {@link #init(ImageLoaderConfiguration)} method wasn't called before\n\t * @throws IllegalArgumentException if passed <b>imageAware</b> is null\n\t */\n\tpublic void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options,\n\t\t\tImageSize targetSize, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {\n\t\tcheckConfiguration();\n\t\tif (imageAware == null) {\n\t\t\tthrow new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);\n\t\t}\n\t\tif (listener == null) {\n\t\t\tlistener = defaultListener;\n\t\t}\n\t\tif (options == null) {\n\t\t\toptions = configuration.defaultDisplayImageOptions;\n\t\t}\n\n\t\tif (TextUtils.isEmpty(uri)) {\n\t\t\tengine.cancelDisplayTaskFor(imageAware);\n\t\t\tlistener.onLoadingStarted(uri, imageAware.getWrappedView());\n\t\t\tif (options.shouldShowImageForEmptyUri()) {\n\t\t\t\timageAware.setImageDrawable(options.getImageForEmptyUri(configuration.resources));\n\t\t\t} else {\n\t\t\t\timageAware.setImageDrawable(null);\n\t\t\t}\n\t\t\tlistener.onLoadingComplete(uri, imageAware.getWrappedView(), null);\n\t\t\treturn;","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/core/ImageLoader.java#L220-L256","documentation":"The full displayImage(uri, imageAware, options, targetSize, listener, progressListener) overload rejects a null imageAware (ImageView wrapper) with IllegalArgumentException(ERROR_WRONG_ARGUMENTS). Every internal variant (displayImage(String, ImageView), displayImage(String, ImageAware, ...)) delegates here, so the ImageView/ImageAware argument must be non-null in all of them. Loading into a null view is almost always a lifecycle bug (view already destroyed), so it fails fast.","triggerScenarios":"ImageLoader.getInstance().displayImage(uri, (ImageView) null); passing an ImageAware whose wrapped view was nulled by onDestroy; async callbacks (e.g. listener futures, event bus handlers) capturing a view reference after the fragment's view was destroyed and set to null.","commonSituations":"Fragment/adapter async completion where the view field was cleared in onDestroyView; findViewById returning null before the layout was inflated; recycled holders whose ImageView field was reset; Kotlin code with a nullable ImageView passed straight through.","solutions":["Null-check views captured by async callbacks before calling displayImage: if (imageView != null) ...","Clear pending callbacks or use the library's own task cancellation (ImageLoader.cancelDisplayTask(imageAware)) in onDestroyView","Ensure displayImage is called after setContentView/onViewCreated, not in onCreate before inflation"],"exampleFix":"// before\nsomeApi.fetch(url, new Callback() {\n    public void done(String uri) {\n        ImageLoader.getInstance().displayImage(uri, holder.imageView); // null after recycle\n    }\n});\n\n// after\nsomeApi.fetch(url, new Callback() {\n    public void done(String uri) {\n        ImageView iv = holder.imageView;\n        if (iv != null) ImageLoader.getInstance().displayImage(uri, iv);\n    }\n});","handlingStrategy":"type-guard","validationCode":"if (imageAware != null && imageAware.getWrappedView() != null) {\n    ImageLoader.getInstance().displayImage(uri, imageAware, options);\n}","typeGuard":"static boolean isDisplayable(ImageAware aware) {\n    return aware != null && aware.getWrappedView() != null;\n}","tryCatchPattern":null,"preventionTips":["Null-check views captured in async callbacks before use","Cancel pending display tasks in onDestroyView via ImageLoader.cancelDisplayTask(imageAware)","Only call displayImage after the view hierarchy is inflated"],"tags":["api-misuse","null-safety","lifecycle","view"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}