一、The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
当我们的代码出现这个错误时:The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files;就是当你在myeclipse引用了不同版本。
由于我用的Myeclipse 版本为6.5,而JDK的版本是1.8的,因此两者版本不兼容,解决方案将是:
1、将JDK的版本降级成1.6的就可以了。
2、也可以将Myeclipse的版本升级。
二、使用Junit4报下面的错误:
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at java.sec
解决:缺少jar包hamcrest-core-1.3.jar,添加这个包
junit4.11.jar要和hamcrest-core-1.3.jar一块使用。
三、spring配置数据源问题:
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type ‘java.lang.String’ to required type ‘javax.sql.DataSource’ for property ‘dataSource’; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property ‘dataSource’: no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:473)
问题:无法将数据源dataSource转换为String字符串,查看数据源配置文件,修改value为ref。
四、单元测试时报编码异常
1、Unknown initial character set index ‘255’ received from server. Initial client character set can be
解决:在数据库连接后面加上下面语句就可以了。
?useUnicode=true&characterEncoding=utf8
2、Unknown system variable ‘tx_isolation’
解决:mysql的连接包版本太低了,之前用的是5.1的,但是我的mysql数据库是8.0的,因此更换高版本的包mysql-connector-java-8.0.11.jar。
3、“com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0” java.lang.UnsupportedClassVersionError: com/mysql/cj/jdbc/Driver : Unsupported major.minor version 52.0
解决:jdk换高版本,换成jdk1.8。
五、新建一个自定义异常类时,package上面总是报错,如下:
The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files
解决:①添加Myeclipse下自带的 jdk libraries
右击project–》properties—》java bulid path----》libraries----》add library----》
②将JDK的版本降低到jdk1.6,但是我的项目不能降低jdk的版本,因此选择第一方案。
点击Next按钮后,继续下面操作上面问题就解决啦
六、java项目打成war包的方法
1、通过cmd直接打包,在tomcat目录下面找到对应的项目,执行 jar -cvf 项目名称.war,然后在此目录下将直接生成mycms.war包
2、通过Eclipse直接导出war包,这个先要在Eclipse中安装导出war包的插件,然后直接导出就可以了
七、后台通过sql直接查询出sum聚合函数求和的数据通过List进行接收后,遍历Object时报类型转换错误,如下:
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to [Ljava.lang.Object;
解决方法:将List转成Objec [] arr 数组则不报错了,如下:
List<Object> countList = getCountByType(dropBean.getValue());
Object [] arr = (Object[]) countList.toArray();