0

I have a problem while loading a TIFF Image. I use ImageIO.read(Test.class.getResourceAsStream(url)) to read an image, with a JPEG it works perfect, but with a TIFF image I get a NullPointerException. The JPEG image and TIFF image are in the same folder.

Edit: Stacktrace

java.lang.NullPointerException 
    at de.test.test1.files.Konstantenbeleg.<init>(Konstantenbeleg.java:47) 
    at de.test.test1.files.Konstantenbeleg.<init>(Konstantenbeleg.java:72)
    at de.de.test.test1.worker.zv.WorkerZVDZService. sendFiles(WorkerZVDZService.java:119)
    at de.de.test.test1.worker.zv.WorkerZV.workJob(WorkerZV.java:73)
    at de.de.test.test1.listener.action.scan. MyScanJobListener.finalzeScan(MyScanJobListener.java:65)
    at de.de.test.test1.listener.action.scan. MyScanJobListener.scanJobNoMoreEvents(MyScanJobListener.java:156)
    at jp.co.ricoh.dsdk.core.function.ScanJobImpl.fire(Unknown Source)
    at jp.co.ricoh.dsdk.core.function.ScanJobImpl.access$200(Unknown Source)
    at jp.co.ricoh.dsdk.core.function.ScanJobImpl$JobEventHandler.exec(Unknown Source)
    at jp.co.ricoh.dsdk.core.manager.EventRunner$Dispatcher.processEvent(Unknown Source)
    at jp.co.ricoh.dsdk.core.manager.EventRunner$Dispatcher.run(Unknown Source)
Kenster
  • 23,465
  • 21
  • 80
  • 106
  • Where is your stack trace? Are you getting the `NullPointerException` from the `ImageIO.read()` invocation, or some other line? Most likely @ReneM is correct, you need to install a TIFF `ImageReader` plugin, but there's not enough detail in the question to say for sure. – Harald K Apr 25 '16 at 10:26

1 Answers1

0

As you can read in the Java Docs of JRE:

Returns a BufferedImage as the result of decoding a supplied InputStream with an ImageReader chosen automatically from among those currently registered. The InputStream is wrapped in an ImageInputStream. If no registered ImageReader claims to be able to read the resulting stream, null is returned.

Source: https://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageIO.html#read(java.io.InputStream)

This method will return null if there is no ImageReader registered for the desired format.

As I see there is no TIFF Image Reader included in standard JRE API. After some googling I found this: http://download.java.net/media/jai-imageio/javadoc/1.1/com/sun/media/imageio/plugins/tiff/package-summary.html

The educational answer of your question is:

Get an ImageReader Impl. which can decode TIFF Images. Register this ImageReader so the ImageIO.read method can determine this reader as the one for your TIFF image.

Rene M.
  • 2,660
  • 15
  • 24
  • What you actually mean with register this ImageReader? I have the lib JAI in my project and the lib plugin imageio-tiff. The Nullpointer i get if i try to use toString() Methode. – Vadim Grigorev Apr 25 '16 at 11:06
  • Look here: http://stackoverflow.com/questions/17178591/how-to-add-tiff-imagereader-to-those-registered-in-grails/17186178#17186178 – Rene M. Apr 25 '16 at 11:10