刚开始学习jfinal 微信 项目 查找时遇到 java.lang.NullPointerException 错误,请问什么原因


package com.javen.model;


import java.util.List;

import java.util.Map;


import com.jfinal.kit.StrKit;

import com.jfinal.log.Log;

import com.jfinal.plugin.activerecord.Model;

import com.jfinal.plugin.activerecord.Page;

import com.jfinal.plugin.ehcache.CacheKit;

import com.jfinal.plugin.ehcache.IDataLoader;


/**

 * 授权获取到的用户信息

 * @author Javen

 */

public class Student extends Model<Student> {


private static final long serialVersionUID = 6204222383226990020L;

static Log log = Log.getLog(Student.class);

public static final Student dao = new Student();

public List<Student> getAll(){

return dao.find("select * from Student");

}


/**

* 所有 sql 与业务逻辑写在 Model 或 Service 中,不要写在 Controller 中,养成好习惯,有利于大型项目的开发与维护

*/

public Page<Student> paginate(int pageNumber, int pageSize) {

return paginate(pageNumber, pageSize, "select *", "from Student order by id asc");

}

public Student findByStudentName(String studentName){

return this.findFirst("select * from student where studentname=?", studentName);

}

public Student findByStudentCode(String studentCode){

return this.findFirst("select * from student where studentcode=?", studentCode);

}


public Student findByPersonCode(String personCode){

return this.findFirst("select * from student where personcode=?", personCode);

}

/**

* 根据map参数查找

* @param paras

* @return 

*/

public List<Student> findByMap(Map<String, Object> paras) {

StringBuilder sql = new StringBuilder("select * from Student ");

if (paras.containsKey("order")) {

sql.append(" ORDER BY ");

sql.append(paras.get("order"));

sql.append(" ");

}

if (paras.containsKey("limit")) {

sql.append(" LIMIT ");

sql.append(paras.get("limit"));

}

return this.findByCache("tenMinute", "Student", sql.toString());

}

}


以下是异常信息


[ERROR]-[Thread: qtp1105085593-25]-[com.jfinal.core.ActionHandler.handle()]: /ajax/bindingStudent

java.lang.NullPointerException

at com.jfinal.plugin.activerecord.Model.find(Model.java:583)

at com.jfinal.plugin.activerecord.Model.findFirst(Model.java:601)

at com.javen.model.Student.findByStudentCode(Student.java:43)

at com.javen.controller.AjaxController.bindingStudent(AjaxController.java:81)

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 com.jfinal.aop.Invocation.invoke(Invocation.java:73)

at com.jfinal.validate.Validator.intercept(Validator.java:86)

at com.jfinal.aop.Invocation.invoke(Invocation.java:67)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74)

at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:75)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)

at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)

at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)

at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560)

at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)

at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)

at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)

at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)

at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)

at org.eclipse.jetty.server.Server.handle(Server.java:365)

at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)

at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)

at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)

at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)

at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)

at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)

at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)

at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)

at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)

at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)

at java.lang.Thread.run(Thread.java:745)


student.class  我是直接复制的TUser.java,


麻烦问下各位大神,这个问题怎么解决啊??


评论区

这个程序员丿不太冷

2018-01-17 10:33

控制台都给你说了,第几行有问题啊,直接点过去,打断点看啊,这个空指针异常很好处理的

JFinal

2018-01-17 12:12

一定要学会调试程序, null pointer exception 是没有任何回答空间的,就是某个对象为 null,然后你调用了这个 null 的方法,或使用了 null 的属性

Dreamlu

2018-01-17 17:20

目测 model 没绑定

智诚博辉

2018-01-17 19:04

@dreamlu 你说的对,是没有绑定Model

智诚博辉

2018-01-17 19:05

初学jfinal,很多还不是很熟的地方,谢谢各位不吝指导

lyh061619

2018-01-18 12:33

请把问题移至反馈版块,当前为分享版块,感谢配合。

devotion

2018-03-13 11:04

@智诚博辉 楼主这个问题怎么解决的?我也遇到这个问题

热门分享

扫码入社