java.lang.ArrayIndexOutOfBoundsException at sun.font.CompositeFont.getSlotFont
来源:互联网 发布:杭州萨满网络 编辑:程序博客网 时间:2024/04/29 01:28
系统环境:
CentOS7
Java 1.8.0_151
Java生成验证码代码如下:
// 在内存中创建图象 int width = 80, height = 30; BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB); // 获取图形上下文 Graphics2D g = image.createGraphics(); // 生成随机类 Random random = new Random(); // 设定背景色 g.setColor(getRandColor(200, 250)); g.fillRect(0, 0, width, height); // 设定字体 g.setFont(new Font("微软雅黑", Font.PLAIN, 18)); // 随机产生180条干扰线,使图象中的认证码不易被其它程序探测到 g.setColor(getRandColor(160, 200)); for (int i = 0; i < 180; i++) { int x = random.nextInt(width); int y = random.nextInt(height); int xl = random.nextInt(12); int yl = random.nextInt(12); g.drawLine(x, y, x + xl, y + yl); } // 取随机产生的认证码(6位数字) String sRand = ""; for (int i = 0; i < 4; i++) { String rand = String.valueOf(CaptchaUtil.getRandomChar()); sRand += rand; // 将认证码显示到图象中 g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110))); // 调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成 g.drawString(rand, 20 * i + 2, 25); } request.getSession().setAttribute("PPFUND_VERIFY_CODE", sRand); // 图象生效 g.dispose(); ServletOutputStream responseOutputStream = response.getOutputStream(); // 输出图象到页面 ImageIO.write(image, "JPEG", responseOutputStream); // 以下关闭输入流! responseOutputStream.flush();
在Windows系统中可以生成图片并正确显示验证码,但在Linux系统中无法生成图片,或者可以生成图片,但不能显示验证码,报错如下:
java.lang.ArrayIndexOutOfBoundsException: 0 at sun.font.CompositeFont.getSlotFont(CompositeFont.java:351) at sun.font.CompositeGlyphMapper.initMapper(CompositeGlyphMapper.java:81) at sun.font.CompositeGlyphMapper.<init>(CompositeGlyphMapper.java:62) at sun.font.CompositeFont.getMapper(CompositeFont.java:409) at sun.font.GlyphList.mapChars(GlyphList.java:269) at sun.font.GlyphList.setFromChars(GlyphList.java:262) at sun.java2d.pipe.GlyphListPipe.drawChars(GlyphListPipe.java:103) at sun.java2d.SunGraphics2D.drawChars(SunGraphics2D.java:3036)
解决办法:
g.setFont(new Font("微软雅黑", Font.PLAIN, 18));
修改为
g.setFont(new Font("STIX", Font.PLAIN, 18));
阅读全文
0 0
- java.lang.ArrayIndexOutOfBoundsException at sun.font.CompositeFont.getSlotFont
- 验证码linux下出不来的问题 java.lang.ArrayIndexOutOfBoundsException at sun.font.CompositeFont.getSlotFont
- java.lang.ArrayIndexOutOfBoundsException 翻译
- java.lang.ArrayIndexOutOfBoundsException
- java.lang.ArrayIndexOutOfBoundsException
- java.lang.ArrayIndexOutOfBoundsException: 3184
- java.lang.ArrayIndexOutOfBoundsException ireport
- java.lang.ArrayIndexOutOfBoundsException
- java.lang.ArrayIndexOutOfBoundsException
- java.lang.ArrayIndexOutOfBoundsException: 2
- [java.lang.arrayindexoutofboundsexception]错误!
- java.lang.ArrayIndexOutOfBoundsException: 160
- java.lang.ArrayIndexOutOfBoundsException
- java.lang.ArrayIndexOutOfBoundsException: 24444
- java.lang.ArrayIndexOutOfBoundsException
- java.lang.ArrayIndexOutOfBoundsException
- java java.lang.ArrayIndexOutOfBoundsException: 1
- Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 69760 at MyFirstApp.main(MyFir
- java集合框架-HashMap
- Windows
- 营业执照如何完整的转为Word格式?
- Deep Learning笔记(四) caffe源码解析
- 冒泡排序
- java.lang.ArrayIndexOutOfBoundsException at sun.font.CompositeFont.getSlotFont
- JavaScript中构造函数及原型介绍
- 《java与模式》-11 适配器模式
- 11.6 校内赛 Set 解题报告【抽屉原理】
- enum of Kotlin
- String
- webbrowser屏蔽网页弹出框
- Intel与Motorola的编码格式
- bzoj1491