java -工作中遇到的异常问题及解决集锦

1 Exception in thread "main" java.lang.UnsupportedClassVersionError: com/mysql/jdbc/Driver : Unsupported major.minor version 52.0

52是什么鬼?参照https://www.cnblogs.com/xing901022/p/4172410.html

  得知

 JDK不同的版本,编译出的class文件是不同的。通过查看分析class文件前几个字节,可以找到对应的关系,详细的参考官方,细微的版本之间可能有差异

1 J2SE 7 = 51 (0x33 hex),
2 J2SE 6.0 = 50 (0x32 hex),
3 J2SE 5.0 = 49 (0x31 hex),
4 JDK 1.4 = 48 (0x30 hex),
5 JDK 1.3 = 47 (0x2F hex),
6 JDK 1.2 = 46 (0x2E hex),
7 JDK 1.1 = 45 (0x2D hex).

我的jdk版本是1.7,驱动要求的是52.0对应的 jdk版本

2 碰到如下异常

 Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
	at org.hibernate.cfg.Configuration.(Configuration.java:165)
	at com.msyd.hibernate.App.main(App.java:12)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 2 more

	at org.hibernate.cfg.Configuration.(Configuration.java:165)
	at com.msyd.hibernate.App.main(App.java:12)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 2 more

解决方案,缺jar包:slf4j-api-1.5.8.jar ,slf4j-log4j12.jar

 

3 使用aspectj加载配置文件出现如下问题:

 Loading XML bean definitions from class path resource [aspectj.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [aspectj.xml]; nested exception is java.io.FileNotFoundException: class path resource [aspectj.xml] cannot be opened because it does not exist
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
	at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
	at com.msyd.spring.aop.aspectj.App.main(App.java:8)
Caused by: java.io.FileNotFoundException: class path resource [aspectj.xml] cannot be opened because it does not exist
	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
	... 13 more

解决方案:

之前写的加载文件ApplicationContext ac = new ClassPathXmlApplicationContext("aspectj.xml");但是它要求必须在类路径下,但我的配置文件不在,所以改为

ApplicationContext ac = new ClassPathXmlApplicationContext("aspectj.xml", App.class); 就可以 了,表示和App.class通路径,加载该xml配置文件。

3 Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 15

Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 15
	at javassist.CtClassType.getClassFile2(CtClassType.java:204)
	at javassist.CtClassType.subtypeOf(CtClassType.java:304)
	at javassist.CtClassType.subtypeOf(CtClassType.java:319)
.....................

Caused by: java.io.IOException: invalid constant type: 15
	at javassist.bytecode.ConstPool.readOne(ConstPool.java:1113)
	at javassist.bytecode.ConstPool.read(ConstPool.java:1056)
	at javassist.bytecode.ConstPool.(ConstPool.java:150)
	at javassist.bytecode.ClassFile.read(ClassFile.java:765)
	at javassist.bytecode.ClassFile.(ClassFile.java:109)
	at javassist.CtClassType.getClassFile2(CtClassType.java:191)
	... 117 more
 

原因之一
https://blog.csdn.net/zhoukun1008/article/details/76602577#commentBox

原因之二进一步解决
https://www.cnblogs.com/yinfj/p/7833932.html

原因之三最狗血:
本地jdk版本过高。比如我用1.8,但是不成,改成1.7就ok了。
4 java.util.zip.ZipException:invalid distance distance too far back

java.util.zip.ZipException:invalid distance distance too far back

这个错误,对于使用maven的童鞋来说应该是可能会遇到过。。。

这个原因就是maven下载相关jar包时未下载完全,导致服务器进行加载解压时出错。

这个就需要查看相关日志,找到没有下载完全的包进行手动下载。

5 org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.OutOfMemoryError: PermGen space

原因是 内存不足,需要将ide的内存设置大一点

 

 

你可能感兴趣的:(mysql数据库操作等,持久层)