javax.ImageIO methods fail silently

你说的曾经没有我的故事 提交于 2019-12-13 04:45:24

问题


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);

回答1:


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.



来源:https://stackoverflow.com/questions/33179187/javax-imageio-methods-fail-silently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!