空指针异常

来源:2-3 用户业务逻辑接口和类

weibo_早起真的好难_0

2016-01-08 16:13

java.lang.NullPointerException

at service.impl.UsersDAOImpl.usersLogin(UsersDAOImpl.java:23)

at com.tarena.test.TestUsersDAOImpl.testUsersLogin(TestUsersDAOImpl.java:17)

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.internal.runners.TestMethod.invoke(TestMethod.java:59)

at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)

at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)

at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)

at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)

at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)

at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)

at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)

at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)

at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)

at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)

at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)




UsersDAOImpl类

Session session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession();

tx = session.beginTransaction();

hql = "from t_user where t_id=? and t_password=?";

Query query = session.createQuery(hql);

query.setParameter(0, u.getId());

query.setParameter(1, u.getPassword());

List list = query.list();

tx.commit();


MyHibernateSessionFactory类

public static SessionFactory getSessionFactory()

{

if(sessionFactory==null)

{

Configuration cfg=new Configuration().configure();

ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();

SessionFactory factory=cfg.buildSessionFactory(serviceRegistry);

return sessionFactory;

}

else{

return sessionFactory;

}

}

    

写回答 关注

2回答

  • DHChan
    2016-04-24 13:48:45

    同,求解

  • 仙人掌的吻
    2016-01-09 12:15:47

    UsersDaoImpl里的语句没有错,你把TesUsersLogin里的代码拿出来看看!

使用Struts2+Hibernate开发学生信息管理功能

Strust2+Hibernate整合开发案例,Java Web开发技能更上一层楼

80701 学习 · 754 问题

查看课程

相似问题