javax.ImageIO方法静默失败 [英] javax.ImageIO methods fail silently

查看:121
本文介绍了javax.ImageIO方法静默失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的Java代码调用了任何javax.ImageIO方法,它将引发一个静默错误. 例如

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

不会产生任何错误消息,但是代码会在此时停止. 我尝试调用ImageIO.getReaderFormatNames()只是为了查看,但它还会引发一个静默错误. 在安装了oracle jre(java版本"1.8.0_60")的Ubuntu中会发生此问题. 请注意,相同的代码在Windows(10)中可以很好地工作. 我也尝试过FileInputStream

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

推荐答案

在@MadProgrammer建议我捕获Throwable而不是Exception进行调试之后,我解决了该问题.我发现我的Ubuntu 15.04计算机未安装libxtst6,导致出现以下错误

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

最终导致以下NoClassDefFoundError

which ended up causing the following NoClassDefFoundError

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

我的Java版本是1.8.0_60 希望它能帮助其他面临类似问题的人.

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

这篇关于javax.ImageIO方法静默失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆