Error instantiating class with invalid types () or values ()
2015-12-23 21:41
513 查看
在使用mysql时,遇到了该错误,详细错误日志如下
以下内容摘自:http://blog.csdn.net/dingsai88/article/details/43670279
1. model中的get/set方法与成员变量不一。
2. 构造函数被重载过,但是没有空的构造函数。
3. 最好不要使用简单类型,如int, long等,改用对象模式Integer, Long等。在写条件查询时会用到判断<if xxx != null > … </if>的
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.panda.test1.User with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.panda.test1.User.<init>() ### The error may exist in com/panda/test2/userMapper.xml ### The error may involve com.panda.test2.userMapper.getUser-Inline ### The error occurred while setting parameters ### SQL: select * from users where id=? ### Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.panda.test1.User with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.panda.test1.User.<init>() at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:59) at com.panda.test2.Test2.testGetUser(Test2.java:57) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.panda.test1.User with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.panda.test1.User.<init>() at org.apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:83) at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:45) at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:38) at org.apache.ibatis.executor.resultset.FastResultSetHandler.createResultObject(FastResultSetHandler.java:376) at org.apache.ibatis.executor.resultset.FastResultSetHandler.createResultObject(FastResultSetHandler.java:355) at org.apache.ibatis.executor.resultset.FastResultSetHandler.getRowValue(FastResultSetHandler.java:255) at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleRowValues(FastResultSetHandler.java:214) at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSet(FastResultSetHandler.java:186) at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSets(FastResultSetHandler.java:152) at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:57) at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:57) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101) ... 26 more Caused by: java.lang.NoSuchMethodException: com.panda.test1.User.<init>() at java.lang.Class.getConstructor0(Class.java:2892) at java.lang.Class.getDeclaredConstructor(Class.java:2058) at org.apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:57) ... 42 more错误原因是,User.java类中没有默认的无参构造函数,加上无参构造函数后,错误消失。
以下内容摘自:http://blog.csdn.net/dingsai88/article/details/43670279
1. model中的get/set方法与成员变量不一。
2. 构造函数被重载过,但是没有空的构造函数。
3. 最好不要使用简单类型,如int, long等,改用对象模式Integer, Long等。在写条件查询时会用到判断<if xxx != null > … </if>的
相关文章推荐
- 【leetcode题解】[E][52]303. Range Sum Query - Immutable
- TimesTen_创建序列(sequence)
- UICollectionViewCell
- UI01_UILabel
- 基于duilib的多标签简易浏览器
- UIView
- com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'rdate'
- 利用 druid 解析器解析SQL
- android125 zhihuibeijing 缓存
- leetcode -- Distinct Subsequences -- DP重点
- leetcode刷题日记——Implement Stack using Queues
- 三大GUI库——AWT、swing、SWT
- Android之UI圆角矩形,图形圆角美化
- 超级简单的UGUI血条制作技巧
- 关于easyUI在子页面增加显示tabs的一个问题
- KVO(NSKeyValueObserving)
- EasyUI Datebox 日期框
- UITableView 视觉差效果
- 在NSString NSNumber NSValue 中一些基本方法的使用和解释
- Material Design UI Widgets