bo的代码:
/*
 * 创建日期 2005-5-9
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
package bos;import daos.*;
import example.domain.*;
import com.ibatis.sqlmap.client.*;
import com.ibatis.common.resources.*;
import java.io.*;
import java.util.List;/**
 * @author Administrator
 *
 * TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class PersonBO {
private SqlMapClient client; public PersonBO() {
try {
Reader reader = Resources.getResourceAsReader("myconfig/sql_map_config.xml");
SqlMapClient client = SqlMapClientBuilder.buildSqlMapClient(reader);
int i;
                i=1;
                } catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
} public void create(Person person) {
PersonDAO personDAO = new PersonDAO(client);
personDAO.insert(person);
} public void update(Person person) {
PersonDAO personDAO = new PersonDAO(client);
personDAO.update(person);
} public void delete(int id) {
PersonDAO personDAO = new PersonDAO(client);
personDAO.delete(id);
} public List findAll() {
PersonDAO personDAO = new PersonDAO(client);
return personDAO.findAll();
} public Person findOne(int id)
{
PersonDAO personDAO=new PersonDAO(client);
return personDAO.findById(id);
}
}action:
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.4/xslt/JavaClass.xslpackage actions;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import bos.*;
import java.util.*;/** 
 * MyEclipse Struts
 * Creation date: 05-09-2005
 * 
 * XDoclet definition:
 * @struts:action validate="true"
 */
public class Index extends Action { // --------------------------------------------------------- Instance Variables // --------------------------------------------------------- Methods /** 
 * Method execute
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
    PersonBO personBO=new PersonBO();
    List list=null;
    list=personBO.findAll();//运行到这行就报错,查询所有注册的用户
    request.setAttribute("person",list);
return mapping.findForward("success");
}
}报错信息:
java.lang.NullPointerException at daos.PersonDAO.findAll(PersonDAO.java:76) at bos.PersonBO.findAll(PersonBO.java:53) at actions.Index.execute(Index.java:44) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:534)用开源的框架调试真是麻烦,大家估计一下吧,什么原因?

解决方案 »

  1.   

    判断一下client 吧,估计那个是null
      

  2.   

    client我跟踪了,并不是null。所以我才奇怪啊
      

  3.   

    一眼就看到错误的地方了
    select per_id as id,per_first_name as firstName第四个id在你前面的
    <resultMap class="example.domain.Person" id="map_person">
    <result property="id" column="per_id"></result>
    <result property="firstName" column="per_first_name"></result>
    <result property="lastName" column="per_last_name"></result>
    <result property="birthDate" column="per_birth_date"></result>
    <result property="weight" column="per_column_kg"></result>
    <result property="height" column="per_height_m"></result> </resultMap>
    根本没有定义,你还没有理解<result property="id" column="per_id"></result>这句话的含义,建议再看看文档
      

  4.   

    ipqitfk(灵魂出走)说的那个地方我根本没有调用,我调用的是getAllPerson,和这个没关系
      

  5.   


    Sorry to reply in english because i type PINGYIN so late :-(Just a suggestion:i think the reason is that JDBC doesn't know the JDBC type 
    when the column is NULL so it cann't convert it into the 
    proper java type.for the column that may be NULL, you can define a parameterMap
    in which you can define its Java type & JDBC type , and even
    you can define the default value when it is really NULL.
    (it is awsome that so many definition should be written )i've not used iBATIS before but we are going to use it for
    our current project, as use the following architecture:
      Struts + SpringFramework + iBATIS
    and that seems feeling well. (REALLY????)
    maybe you can mail me to talk about some of that.To XiaoXu:
    i'm sorry that i have no time to test what i said above, so
    would you please do me a favour to write some code to test
    it? and please tell us the result so we need to test it ourselves.
    Thanks.
      

  6.   

    Just again.a suggestion again:the original SqlMap definition:
    ----------------------------------------------------------
    <resultMap class="example.domain.Person" id="map_person">
    <result property="id" column="per_id"></result>
    <result property="firstName" column="per_first_name"></result>
    <result property="lastName" column="per_last_name"></result>
    <result property="birthDate" column="per_birth_date"></result>
    <result property="weight" column="per_column_kg"></result>      <--------!!!!!!!!!
    <result property="height" column="per_height_m"></result>
    </resultMap>
    ----------------------------------------------------------Just notice 
       <result property="weight" column="per_column_kg"></result>      <--------!!!!!!!!!the correct column name is "per_weight_kg" and NOT ="per_column_kg".
    maybe that the REAL reason. so just correct it and try.
      

  7.   

    to zhuzy:
      1.表里的数据没有为null的
     2. <result property="weight" column="per_column_kg"></result> <--------!!!!!!!!!这个地方是笔误,已经改了
     3.又发现一处错误,没有建立相应的用户,在sqlserver中
      

  8.   

    没有执行,就不是错了吗?既然挂出帖子来,就不要怕大家批评。
    言归正传,
    你贴出的
    <select id="getAllPerson" resultMap="map_person">
    &lt;![CDATA[
              select * from person
            ]]&gt;
    </select>&lt;!是代码里就这样,还是??
      

  9.   

    <select id="getAllPerson" resultMap="map_person">
    &lt;![CDATA[
    select * from person
    ]]&gt;
    </select>
      

  10.   

    Maybe the probrom is in the Java class.public class PersonBO {
    private SqlMapClient client;public PersonBO() {
    try {
    Reader reader = Resources.getResourceAsReader("myconfig/sql_map_config.xml");
    //SqlMapClient client = SqlMapClientBuilder.buildSqlMapClient(reader);
    //local varity
    client = SqlMapClientBuilder.buildSqlMapClient(reader);
    int i;
    i=1;
    }
    ...
    public class PersonDAO {
    ...
    public List findAll()
    {
    List list=null;
    try {
    //list=client.queryForList("Person.getAllPerson",null);
    //no namespace
    list=client.queryForList("getAllPerson",null);
    int i;
    i=0;
    }
    ....
    }.....
      

  11.   

    Chenshy and i read your code and find 
    that there are at least 2 bugs in your 
    code:(1)You use namespace in your code but you
       make definition to use no namespace in your
       "sqlMapConfig".
       xml:
         useStatementNamespaces="false"  <-----this is false
       source code:
         client.delete("Person.delete",person); <--using namespace of "Person"(2) the direct reason is that you use the instance varibal 
       named "client" (line 4 of the following code) to transfer 
       the reference of SqlMapClient to the other objects as input 
       (see the line 14 in the following code).
       
       BUT, JUST SEE LINE 9. You build the SqlMapClient object there but
       you defined it as a local varible using the same name as "client".
       That means, although you build the SqlMapClient successfully
       and the "client" varible of line 9 is not null, it is only 
       a LOCAL varible so it is OUT OF RANGE after line 12.
       so just correct it as the following:
         before:  SqlMapClient client = SqlMapClientBuilder.buildSqlMapClient(reader);
         after:   client = SqlMapClientBuilder.buildSqlMapClient(reader);
       then the varible of "client" is the instance varibal (property) 
       of PersonBO as is defined at line 4. So it will go well. Your code:
    ----------------------------------------------------

    2
    3  public class PersonBO {
    4   private SqlMapClient client;             <--**** instance varibal definition           
    5  
    6   public PersonBO() {
    7   try {
    8   Reader reader = .....
    9   SqlMapClient client = SqlMapClientBuilder.buildSqlMapClient(reader); <--**local varibal definition  
    10   int i;
    11   i=1;
    12   }
       ...
      
    13  public void update(Person person) {
    14      PersonDAO personDAO = new PersonDAO(client);   <----*** use "client" to transfer SqlMapClient reference
    15      personDAO.update(person);
    16  }
      
    ----------------------------------------------------
      Regards.