使用ZXing生成二维码,识别JVM版本的时候出错?
各位前辈,我使用谷歌的ZXing创建二维码,按照网上的例子写。刚开始可以运行,然后我在其他Service里面打了个断点,调试了一下其他问题,再运行这个地方就报错了。
例子:
BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE,width,height,hints);
Path file = new File("C:/Users/Administrator/Desktop/SpringBoot/img.png").toPath();
MatrixToImageWriter.writeToPath(matrix,format,file);
错误信息出在这一步:
MatrixToImageWriter.writeToPath(matrix,format,file);
报错信息是:
Caught and handled this exception :
java.lang.NumberFormatException: For input string: ""
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.base/java.lang.Integer.parseInt(Integer.java:662)
at java.base/java.lang.Integer.parseInt(Integer.java:770)
at com.github.jaiimageio.impl.common.ImageUtil.processOnRegistration(ImageUtil.java:1401)
at com.github.jaiimageio.impl.plugins.bmp.BMPImageReaderSpi.onRegistration(BMPImageReaderSpi.java:97)
at java.desktop/javax.imageio.spi.SubRegistry.registerServiceProvider(ServiceRegistry.java:788)
at java.desktop/javax.imageio.spi.ServiceRegistry.registerServiceProvider(ServiceRegistry.java:330)
at java.desktop/javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(IIORegistry.java:212)
at java.desktop/javax.imageio.spi.IIORegistry.<init>(IIORegistry.java:136)
at java.desktop/javax.imageio.spi.IIORegistry.getDefaultInstance(IIORegistry.java:157)
at java.desktop/javax.imageio.ImageIO.<clinit>(ImageIO.java:66)
at com.google.zxing.client.j2se.MatrixToImageWriter.writeToPath(MatrixToImageWriter.java:129)
at com.google.zxing.client.j2se.MatrixToImageWriter.writeToPath(MatrixToImageWriter.java:100)
at com.scut.originsystem.util.QRCodeUtil.createQRCode(QRCodeUtil.java:42)
at com.scut.originsystem.service.QRCodeService.qRCodeWord(QRCodeService.java:162)
at com.scut.originsystem.service.QRCodeService.asyncQRCodeWord(QRCodeService.java:146)
at com.scut.originsystem.service.QRCodeService$$FastClassBySpringCGLIB$$a6aa6547.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:115)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.lang.Thread.run(Thread.java:844)
报错的源码是:
String jvmVendor = System.getProperty("java.vendor");
String jvmVersionString = System.getProperty("java.specification.version");
int verIndex = jvmVersionString.indexOf("1.");
jvmVersionString = jvmVersionString.substring(verIndex + 2);
int jvmVersion = Integer.parseInt(jvmVersionString);
这里显示jvmVersionString为空,无法转换为int。
这是API的BUG么,应该如何修改?为什么之前可以运行?
请各位前辈指导。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题解决了,ZXing只能识别1.X这种形式的java版本,我的是9.0.X形式的,要System.setProperty("java.specification.version","1.9")就可以运行了
请问一下你用的
ZXing
是哪个版本,具体是用了哪个几个模块???