public void testfindUserById(){
SqlSession sqlSession=null;
try {
sqlSession=sqlSessionFactory.openSession();
User user=sqlSession.selectOne("test.findUserById",10);
System.out.println(user);
} catch (Exception e) {
e.printStackTrace();
}finally{
if(sqlSession!=null){
sqlSession.close();
}
}
}
上面是代码,第31行错误是空指针。但已经初始化。
java.lang.NullPointerException
at com.iss.entity.MyBatisTest.testfindUserById(MyBatisTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod