package com.yihaomen.test; import java.io.Reader; import java.util.List; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import com.yihaomen.mybatis.inter.IUserOperation; import com.yihaomen.mybatis.model.User; public class Test1{ private static SqlSessionFactory sqlSessionFactory; private static Reader reader; public void getUserList(int id){ SqlSession session = sqlSessionFactory.openSession(); try { IUserOperation userOperation=session.getMapper(IUserOperation.class); List<User> users = userOperation.selectUsers(id); for(User user:users){ System.out.println(user.getId()+":"+user.getUserName()+":"+user.getUserAddress()); } } finally { session.close(); } } public static void main(String[] args) { int i=1; Test1 testUser=new Test1(); testUser.getUserList(i); } }
Exception in thread "main" java.lang.NullPointerException at com.yihaomen.test.Test1.getUserList(Test1.java:17) at com.yihaomen.test.Test1.main(Test1.java:32)
解决方案
20
sqlSessionFactory未初始化吧
10
sqlSessionFactory
20
你的reader也是空的