为了账号安全,请及时绑定邮箱和手机立即绑定

空指针异常

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 回答

同,求解

0 回复 有任何疑惑可以回复我~

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

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

空指针异常

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信