请问我这里是什么地方错了  报 500 空指针错误 请帮我看一下 谢谢!
请求链接:
<li><a href="type_findAllType.action" target="mainFrame">类型显示</a></li>struts.xml:<action name="type_*" class="com.action.TypeAction" method="{1}">
<result name="lgnOk">ok.jsp</result>
<result name="showTypeOk">tyepShow.jsp</result>
</action>Action:package com.action;import java.util.List;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.pojo.Pftype;public class TypeAction extends ActionSupport{
//表单
private com.pojo.Pftype type;
//action依赖对象
private com.biz.TypeBizInf typebiz; private List<Pftype> types;


public List<Pftype> getTypes() {
return types;
} public void setTypes(List<Pftype> types) {
this.types = types;
} public com.pojo.Pftype getType() {
return type;
} public void setType(com.pojo.Pftype type) {
this.type = type;
} public com.biz.TypeBizInf getTypebiz() {
return typebiz;
} public void setTypebiz(com.biz.TypeBizInf typebiz) {
this.typebiz = typebiz;
}

//-----------------------------------------------------------------------

public String findAllType(){

 types = typebiz.findType();    //debug模式 到这里停了 提示 空指针 

return "showTypeOk";


}


}service层:Interface:package com.biz;import java.util.List;import com.pojo.Pftype;
public interface TypeBizInf { List<Pftype> findType();

}
Imp:package com.biz;import java.util.List;import com.pojo.Pftype;public class TypeBizImp implements TypeBizInf {

private com.dao.PftypeDAO typedao;
//get set
public com.dao.PftypeDAO getTypedao() {
return typedao;
} public void setTypedao(com.dao.PftypeDAO typedao) {
this.typedao = typedao;
}
public List<Pftype> findType() {
// TODO Auto-generated method stub
return typedao.findAll();
}
}
DAO层:package com.dao;import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.pojo.Pftype;
public class PftypeDAO extends HibernateDaoSupport {
private static final Logger log = LoggerFactory.getLogger(PftypeDAO.class);
// property constants
public static final String NMBER = "nmber";
public static final String TNAME = "tname";
public static final String TYPE_ID = "typeId";
public static final String TIP_ID = "tipId";
public static final String INFO = "info"; protected void initDao() {
// do nothing
} public List findAll() {
log.debug("finding all Pftype instances");
try {
String queryString = "from Pftype";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public static PftypeDAO getFromApplicationContext(ApplicationContext ctx) {
return (PftypeDAO) ctx.getBean("PftypeDAO");
}
}

解决方案 »

  1.   

    空指针错误 就找点 点前面的对象是null你的错误是 typebiz 这个变量是null这个很正常,因为你代码里根本就没实例化这个对象如果你用spring,说明你spring配置错了。
      

  2.   

    请问我代码写了  action的依赖对象:  private com.biz.TypeBizInf typebiz;   这样是否就有typebiz这个对象了?
      

  3.   

    同意3楼     spring 的配置也帖出来看一下  估计是typebiz 没有注进去
      

  4.   

    可以在xml配置,也可以用注解,前提是在spring的配置中把注解打开,类似这样
    @Resource(name = "sjzdServiceImpl")
    private SjzdService sjzdService;
    推荐用注解
      

  5.   

    在spring 中我是这样配置的
    <!-- type -->

    <bean id="TypeBizImp" class="com.biz.TypeBizImp">
    <property name="typedao" ref="PftypeDAO"></property>

    </bean><!-- type -->

    <bean id="TypeAction" class="com.action.TypeAction">
    <property name="typebiz" ref="TypeBizImp"></property>
    </bean>
      

  6.   

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p"

    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"

    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                        
                        http://www.springframework.org/schema/tx 
                        http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
                            http://www.springframework.org/schema/aop
                            http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"
    value="com.mysql.jdbc.Driver">
    </property>
    <property name="url"
    value="jdbc:mysql://127.0.0.1:3306/platform?useunicode=true&amp;characterEncoding=utf8">
    </property>
    <property name="username" value="root"></property>
    <property name="password" value="root"></property>
    </bean>
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLDialect
    </prop>
    </props>
    </property>
    <property name="mappingResources">
    <list>
    <value>com/pojo/Pfgameinfo.hbm.xml</value>
    <value>com/pojo/Pfpwques.hbm.xml</value>
    <value>com/pojo/Pfpicture.hbm.xml</value>
    <value>com/pojo/Pftype.hbm.xml</value>
    <value>com/pojo/Pfadmin.hbm.xml</value>
    <value>com/pojo/Pfserver.hbm.xml</value>
    <value>com/pojo/Pfsmallgameinfo.hbm.xml</value>
    <value>com/pojo/Pfnews.hbm.xml</value>
    <value>com/pojo/Pftopup.hbm.xml</value>
    <value>com/pojo/Pflogin.hbm.xml</value>
    <value>com/pojo/Pfrole.hbm.xml</value>
    <value>com/pojo/Pfuser.hbm.xml</value></list>
    </property></bean>
    <bean id="PfgameinfoDAO" class="com.dao.PfgameinfoDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="PfpwquesDAO" class="com.dao.PfpwquesDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="PfpictureDAO" class="com.dao.PfpictureDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="PftypeDAO" class="com.dao.PftypeDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="PfadminDAO" class="com.dao.PfadminDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="PfserverDAO" class="com.dao.PfserverDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="PfsmallgameinfoDAO" class="com.dao.PfsmallgameinfoDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="PfnewsDAO" class="com.dao.PfnewsDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="PftopupDAO" class="com.dao.PftopupDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="PfloginDAO" class="com.dao.PfloginDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="PfroleDAO" class="com.dao.PfroleDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="PfuserDAO" class="com.dao.PfuserDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>

    <!-- spring声明式事务管理器 -->
    <bean id="hibTransactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <!-- 声明式事务的通知 -->
    <tx:advice id="txAdvice"
    transaction-manager="hibTransactionManager">
    <!-- 指定传播行为 -->
    <tx:attributes>
    <tx:method name="save*" propagation="REQUIRED"/>
    <tx:method name="del*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" />
    <tx:method name="*" propagation="SUPPORTS" read-only="true"/>
    </tx:attributes>
    </tx:advice>

    <aop:config>
    <aop:pointcut id="bizMethods"
    expression="execution(* com.biz.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" />
    </aop:config>




    <!-- biz -->
    <!-- admin -->

    <bean id="AdminBizImp" class="com.biz.AdminBizImp">
    <property name="admindao" ref="PfadminDAO"></property>
    </bean>

    <!-- type -->

    <bean id="TypeBizImp" class="com.biz.TypeBizImp">
    <property name="typedao" ref="PftypeDAO"></property>

    </bean>
    <!-- actions -->
    <!-- admin -->

    <bean id="AdminAction" class="com.action.AdminAction" scope="prototype">
    <property name="adminbiz" ref="AdminBizImp"/>
    </bean>
    <!-- type -->

    <bean id="TypeAction" class="com.action.TypeAction">
    <property name="typebiz" ref="TypeBizImp"></property>
    </bean>


    </beans>
      

  7.   

    这是我spring中的全部代码  还请您帮我看一下 谢谢 感激不尽 !!
      

  8.   

    types = typebiz.findType(); //debug模式 到这里停了 提示 空指针  修改为
    if(typebiz!=null)
    {
    types = typebiz.findType(); 
    }
      

  9.   

    测试后 typebiz 等于 null  不过问题还没找出来@_@
      

  10.   

    你的Action好像没有纳入Spring的管理,所以Spring不会自动帮你装配进去