chenzen
chenzen

Reputation: 73

javax.ImageIO methods fail silently

If my java code makes a call to any javax.ImageIO method, it throws a silent error. e.g.

File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try
{
   BufferedImage fullImg = ImageIO.read(screenshot);
}
catch(Exception e)
{
   e.printStackTrace();
}

no error message is produced, but the code halts at that point. I tried calling ImageIO.getReaderFormatNames() just to see, but it also throws a silent error. This problem occurs in Ubuntu with oracle jre (java version "1.8.0_60") installed. Please note that the same code works perfectly fine in Windows (10). I have tried with FileInputStream as well

FileInputStream fis = new FileInputStream(screenshot);
BufferedImage fullImg = ImageIO.read(fis);

Upvotes: 0

Views: 476

Answers (1)

chenzen
chenzen

Reputation: 73

I solved the problem after @MadProgrammer suggested me to catch Throwable instead of Exception to debug. I found out that my Ubuntu 15.04 machine doesn't have libxtst6 installed, leading to the following error

java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-8-oracle/jre/lib/amd64/libawt_xawt.so: libXtst.so.6: cannot open shared object file: No such file or directory

which ended up causing the following NoClassDefFoundError

java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO

My java version is 1.8.0_60 Hope it helps others facing similar issues.

Upvotes: 2

Related Questions