Breaking News
Home / Java / Java Snippets / No Registered ImageReader claims to be able to read the resulting stream, null is returned.

No Registered ImageReader claims to be able to read the resulting stream, null is returned.

Exception

While trying to read and write image as PNG  with the code sas

BufferedImage image = ImageIO.read(new ByteArrayInputStream(decodedBytes));
            if (image == null) {
                log.error(“Buffered Image is null”);
            }
            File f = new File(uploadFile);

            ImageIO.write(image, “png”, f);<!>

The following error occurs:

2011-12-24 00:23:44,989[Thread-16]ERROR SubscriptionXmlService -Failed to perform subscription upload : java.lang.IllegalArgumentException: im == null!
java.lang.RuntimeException: java.lang.IllegalArgumentException: im == null!
     at com.infuze.service.subscription.workflow.SubscriptionUploadWorkflow.executeProcess(

SubscriptionUploadWorkflow.java:146)
     at com.infuze.service.workflow.WorkflowExecutor.execute(WorkflowExecutor.java:24)
     at com.infuze.service.subscription.xml.SubscriptionXmlService.uploadData(SubscriptionXmlService.java:349)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at com.livrona.xhttpi.XHttpInvoker.execute(Unknown Source)
     at com.infuze.server.service.XmlServiceActionHandler.execute(XmlServiceActionHandler.java:28)
     at com.livrona.haxe.server.RequestHandler.executeRequest(RequestHandler.java:149)
     at com.livrona.haxe.server.RequestHandler.run(RequestHandler.java:77)
Caused by: java.lang.IllegalArgumentException: im == null!
     at javax.imageio.ImageIO.write(ImageIO.java:1457)
     at javax.imageio.ImageIO.write(ImageIO.java:1527)
     at com.infuze.service.subscription.workflow.SubscriptionUploadWorkflow.executeProcess

(SubscriptionUploadWorkflow.java:90)
     … 10 more

Solution

The docs for ImageIO.read state:
If no registered ImageReader claims to be able to read the resulting stream, null is returned.

What is most likely happening here is that the decodedBytes bytes that are the input here are corrupted or do not represent an image (png, jpg etc.) due to which underlying API is not able to find a suitable Reader and the it returns a null causing this exception. Verify the source of the data/bytes most likely there is issue in reading/decoding bytes.

[pb_builder]

Check Also

How to progamatically get the Java version?

Snippet The key here is to use the system property java.version and get minor and …

Advertisment ad adsense adlogger