NutzCN Logo
问答 Dao调用空指针异常
发布于 3034天前 作者 qq_041ad963 2553 次浏览 复制 上一个帖子 下一个帖子
标签:

用到dao.query时 发生空指针,发现是Nutdao的pojoMaker和holder对象为null 。请问这是为何?
程序如下
var ioc = {
dataSource: {
type: "org.apache.tomcat.dbcp.dbcp.BasicDataSource",
singleton: true,
events: {
depose : 'close'
},
fields: {
driverClassName: "com.ibm.db2.jcc.DB2Driver",
url: "jdbc:db2://localhost:50000/QGETC",
username: "db2admin",
password: "111111",
maxWait: 15000,
defaultAutoCommit: false,
validationQuery: "SELECT 'X'",
testWhileIdle: true,
testOnBorrow: false,
testOnReturn: false,
timeBetweenEvictionRunsMillis: 60000,
minEvictableIdleTimeMillis: 300000,
initialSize: 0,
minIdle: 1,
maxActive: 20,
removeAbandoned: true,
removeAbandonedTimeout: 3600000,
poolPreparedStatements: true,
maxPoolPreparedStatementPerConnectionSize: 20 // 指定每个连接上PSCache的大小
}
},
dao : {
type : "org.nutz.dao.impl.NutDao",
fields : {
dataSource : {refer : 'dataSource'}
}
}
};

@Modules({LoginController.class})
@Fail("json")
@IocBy(type=JsonIocProvider.class, args={"./ioc/dao.js"})
public class MainModule {
}

@Ok("json")
public class LoginController {
@At("/yousay")
public String sayMore(@Param("username") String username,
@Param("age") String age) {

    Dao dao = new NutDao();
    List<user> list = dao.query(user.class, null, null);
    String jsonStr = Json.toJson(list);
    return str;
}

}

@Table("TUSER")
public class user {
public user() {}
@Name
private Long userId;
@Column
private String userName;
@Column
private String realName;
@Column
private String passWord;
@Column
private Integer right;
@Column
private Integer active;
getset省略。。。
}

3 回复

log如下
2016-9-1 17:18:52.749 WARN [http-apr-8080-exec-9] Error@/yousay :
java.lang.NullPointerException
at org.nutz.dao.impl.NutDao.query(NutDao.java:459)
at org.nutz.dao.impl.NutDao.query(NutDao.java:470)
at com.web.yxy.controller.LoginController.sayMore(LoginController.java:40)
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.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2522)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2511)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

直接新建NutDao了,不抛错才怪.

Dao dao = new NutDao();

先看看nutzbook吧 http://nutzbook.wendal.net/

我去。。。这么简单的错误都没发现 感谢提醒~~

添加回复
请先登陆
回到顶部