Could not initialize class java.awt.image.BufferedImage

J2EE 码拜 9年前 (2015-04-03) 3558次浏览 0个评论

一个生成验证码的Java代码
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
本地可以生成、访问和在网页上显示,但放到服务器上去了就生成不了,报以下错误
求大神解决!
服务器系统:CentOS 6.5 64位    CPU:x86_64

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class java.awt.image.BufferedImage
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:972)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.mg.freeplay.common.filter.LogonFilter.doFilter(LogonFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class java.awt.image.BufferedImage
at com.mg.freeplay.common.utils.VerifyCode.createCode(VerifyCode.java:78)
at com.mg.freeplay.common.utils.VerifyCode.<init>(VerifyCode.java:35)
at com.mg.freeplay.web.IndexController.verifyCode(IndexController.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
… 28 more

Could not initialize class java.awt.image.BufferedImage
10分
jar包没有放进去吧。
Could not initialize class java.awt.image.BufferedImage
10分
确定服务器上JDK已经安装了
Could not initialize class java.awt.image.BufferedImage
20分
java.lang.NoClassDefFoundError: Could not initialize class java.awt.image.BufferedImage

没有初始化java.awt.image.BufferedImage这个类

Could not initialize class java.awt.image.BufferedImage
引用 2 楼 my_mtx 的回复:

确定服务器上JDK已经安装了

安装了阿,jdk1.6,tomcat 6.0和本地一样的环境,没安装整个程序怎么跑得起来~
这个地址,可以看下:
http://123.57.75.37/userInfo/login

Could not initialize class java.awt.image.BufferedImage
引用 3 楼 u012171905 的回复:

java.lang.NoClassDefFoundError: Could not initialize class java.awt.image.BufferedImage

没有初始化java.awt.image.BufferedImage这个类

怎么初始化??这是jdk自带的吧,求指导

Could not initialize class java.awt.image.BufferedImage
20分
引用 5 楼 u010047583 的回复:
Quote: 引用 3 楼 u012171905 的回复:

java.lang.NoClassDefFoundError: Could not initialize class java.awt.image.BufferedImage

没有初始化java.awt.image.BufferedImage这个类

怎么初始化??这是jdk自带的吧,求指导

at com.mg.freeplay.common.utils.VerifyCode.createCode(VerifyCode.java:78)—-debug这个类看看,78行是什么,调用了什么,出了什么问题

Could not initialize class java.awt.image.BufferedImage
引用 6 楼 u012171905 的回复:
Quote: 引用 5 楼 u010047583 的回复:
Quote: 引用 3 楼 u012171905 的回复:

java.lang.NoClassDefFoundError: Could not initialize class java.awt.image.BufferedImage

没有初始化java.awt.image.BufferedImage这个类

怎么初始化??这是jdk自带的吧,求指导

at com.mg.freeplay.common.utils.VerifyCode.createCode(VerifyCode.java:78)—-debug这个类看看,78行是什么,调用了什么,出了什么问题

buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
就是new的时候出的问题

Could not initialize class java.awt.image.BufferedImage
10分
为什么不去查呢,很多人都在问啊,不说了直接上链接:

http://blog.csdn.net/lee353086/article/details/5793240

Could not initialize class java.awt.image.BufferedImage
引用 8 楼 ooppookid 的回复:

为什么不去查呢,很多人都在问啊,不说了直接上链接:

http://blog.csdn.net/lee353086/article/details/5793240

又不是没查过就来问,那个安装包的地址不可用了,而且感觉比较复杂,不会弄,就想问下有没简单点的做法

Could not initialize class java.awt.image.BufferedImage
10分
引用 9 楼 u010047583 的回复:
Quote: 引用 8 楼 ooppookid 的回复:

为什么不去查呢,很多人都在问啊,不说了直接上链接:

http://blog.csdn.net/lee353086/article/details/5793240

又不是没查过就来问,那个安装包的地址不可用了,而且感觉比较复杂,不会弄,就想问下有没简单点的做法

那就米办法啦 我了看这里的办法,没试过,但是理论上说的有道理,很多32位的东西上64位会有问题。

所以你本地好使,上服务器不好使一般要是应用服务和代码都一致,那就从系统差异找问题,至于如何处理要么凭经验,要么就是查呀查 试一试。

Could not initialize class java.awt.image.BufferedImage
20分
jar包冲突或者 JDK与tomcat 版本号对不上,可以尝试一下。
Could not initialize class java.awt.image.BufferedImage
问题解决了,我是吧服务器换成了32位的系统,重新再做一遍就没问题了~~~感觉这样简单多了,我用的阿里云的服务器,换系统配置需要先关机,

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Could not initialize class java.awt.image.BufferedImage
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!