java.lang.NullPointerException
at action.ClaimVoucherAction.addClaimVoucher(ClaimVoucherAction.java:101)
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 com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
下面是我的action里面的代码
package action;
@Results({ @Result(name = "input", location = "/Index.jsp"),
@Result(name = "list", location = "/list.jsp") })
public class ClaimVoucherAction {
/**
* 报销单主表信息
*/
private BizClaimVoucher claimVoucher = new BizClaimVoucher();
private IItemsBiz itemsBiz;
private IBizClaimVoucherBiz caimVoucherBiz;
List<Items> lists;
private String opr;
/**
* 报销项目明细
*/
private Integer itemId[]; // 报销项目
private Double amount[]; // 报销金额
private String desc[]; // 报销是由
private Map sessionMap = ActionContext.getContext().getSession();
SysEmployee emp = (SysEmployee) sessionMap.get("emp");
private Map requestMap = (Map) ActionContext.getContext().get("request");
/**
* 添加明细
* @return
*/
@Action("addClaimVoucherActon")
public String addClaimVouchers() {
System.out.println("doadd------" + opr);
Double summer=0D; //计算总金额
BizClaimVoucherDetail detail=null;
for (int i = 0; i < itemId.length; i++) {
// 明细信息
detail = new BizClaimVoucherDetail();
detail.setClaimVoucher(claimVoucher);
detail.setAccount(amount[i]); // 金额
summer+=amount[i];
detail.setDes(desc[i]);// 描述
Items items = new Items();// 报销项目
items.setItemsId(itemId[i]);
detail.setItems(items);
// 明细表添加到主表对象中去
claimVoucher.getDetails().add(detail);
}
// 获取报销主表信息
claimVoucher.setNextDealRole(emp);
claimVoucher.setStatus("新创建");//状态
claimVoucher.setCreator(emp);
claimVoucher.setCreateTime(new Date()); //创建时间
claimVoucher.setLastUpdateDate(new Date());//修改时间
claimVoucher.setEvent(claimVoucher.getEvent());
claimVoucher.setLastUpdatedBy(emp.getSn().toString());//创建人
claimVoucher.setTotalAccount(summer);//报销总金额
// 执行save保存报销单信息
try {
caimVoucherBiz.addClaimVoucher(claimVoucher);
} catch (Exception e) {
e.printStackTrace();
}
return "list";
}
//省略 get/set方法
}
下面是我的实现方法
[code=java]
public class BizClaimVoucherDaoImpl extends HibernateDaoSupport implements IBizClaimVoucherDao{
/**
* 添加报销单信息
*/
public void addClaimVoucher(BizClaimVoucher cv) {
this.getHibernateTemplate().save(cv);
}
}
9 个解决方案
#1
这是我的spring.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans">
<bean
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"
id="config">
<property name="locations">
<list>
<value>classpath:dataSource.properties</value>
</list>
</property>
</bean>
<bean class="org.apache.commons.dbcp.BasicDataSource" id="dbConnection">
<property name="url" value="${mysql.url}" />
<property name="driverClassName" value="${mysql.driver}" />
<property name="username" value="${mysql.username}" />
<property name="password" value="${mysql.password}" />
<property name="defaultAutoCommit" value="false" />
</bean>
<!-- 配置Session工厂 -->
<bean
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
id="sFactory">
<!-- 注入dataSource ref指向我们配置的数据源的beanId -->
<property name="dataSource" ref="dbConnection" />
<!-- 配置hibernate的连接参数 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="autocommit">false</prop>
</props>
</property>
<!-- 扫描实体类对应的package -->
<property name="packagesToScan" value="entity" />
</bean>
<!-- 配置事务管理器 -->
<bean class="org.springframework.orm.hibernate3.HibernateTransactionManager"
id="transactionManager">
<property name="sessionFactory" ref="sFactory" />
</bean>
<!-- 配置事务通知,引用事务管理器 -->
<tx:advice id="advice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 所有的insert开头方法,都会由advice来进行管理 -->
<tx:method name="insert*" propagation="REQUIRED" read-only="false"/>
<tx:method name="add*" propagation="REQUIRED" read-only="false"/>
<tx:method name="addClaimVoucher" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- 定义切面编程 -->
<aop:config>
<aop:pointcut id="insertPointCut" expression="execution(* biz..*.*(..))" />
<!-- 使用切面编程,配置事务管理,在业务方法的持久化操作前后加入事务管理 -->
<aop:advisor pointcut-ref="insertPointCut" advice-ref="advice" />
</aop:config>
<!-- 配置事务 -->
<bean id="deptDao" class="dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sFactory" />
</bean>
<bean id="userbiz" class="biz.impl.UserBizImpl" scope="prototype">
<property name="dao" ref="deptDao"></property>
</bean>
<bean id="deptAction" class="action.userAction">
<property name="userbiz" ref="userbiz" />
</bean>
<!-- 报销主表 -->
<bean id="claimVoucherDao" class="dao.impl.BizClaimVoucherDaoImpl">
<property name="sessionFactory" ref="sFactory" />
</bean>
<bean id="claimVoucherBiz" class="biz.impl.BizClaimVoucherBizIMpl">
<property name="cvDao" ref="claimVoucherDao"></property>
</bean>
<bean id="voucherAction" class="action.ClaimVoucherAction" scope="prototype">
<property name="itemsBiz" ref="itemsBiz"></property>
<property name="caimVoucherBiz" ref="claimVoucherBiz"></property>
</bean>
</beans>
#2
#3
private IBizClaimVoucherBiz caimVoucherBiz; 加set方法
#4
private BizClaimVoucher claimVoucher = new BizClaimVoucher();
改成
private BizClaimVoucher claimVoucher;
并加上set方法
改成
private BizClaimVoucher claimVoucher;
并加上set方法
#5
private BizClaimVoucher claimVoucher = new BizClaimVoucher();
是实体类
是实体类
#6
这个是实体类
#7
这个是实体类
#8
java.lang.NullPointerException
at action.ClaimVoucherAction.addClaimVoucher(ClaimVoucherAction.java:101)
看这里
at action.ClaimVoucherAction.addClaimVoucher(ClaimVoucherAction.java:101)
看这里
#9
caimVoucherBiz这个是空的
#1
这是我的spring.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans">
<bean
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"
id="config">
<property name="locations">
<list>
<value>classpath:dataSource.properties</value>
</list>
</property>
</bean>
<bean class="org.apache.commons.dbcp.BasicDataSource" id="dbConnection">
<property name="url" value="${mysql.url}" />
<property name="driverClassName" value="${mysql.driver}" />
<property name="username" value="${mysql.username}" />
<property name="password" value="${mysql.password}" />
<property name="defaultAutoCommit" value="false" />
</bean>
<!-- 配置Session工厂 -->
<bean
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
id="sFactory">
<!-- 注入dataSource ref指向我们配置的数据源的beanId -->
<property name="dataSource" ref="dbConnection" />
<!-- 配置hibernate的连接参数 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="autocommit">false</prop>
</props>
</property>
<!-- 扫描实体类对应的package -->
<property name="packagesToScan" value="entity" />
</bean>
<!-- 配置事务管理器 -->
<bean class="org.springframework.orm.hibernate3.HibernateTransactionManager"
id="transactionManager">
<property name="sessionFactory" ref="sFactory" />
</bean>
<!-- 配置事务通知,引用事务管理器 -->
<tx:advice id="advice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 所有的insert开头方法,都会由advice来进行管理 -->
<tx:method name="insert*" propagation="REQUIRED" read-only="false"/>
<tx:method name="add*" propagation="REQUIRED" read-only="false"/>
<tx:method name="addClaimVoucher" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- 定义切面编程 -->
<aop:config>
<aop:pointcut id="insertPointCut" expression="execution(* biz..*.*(..))" />
<!-- 使用切面编程,配置事务管理,在业务方法的持久化操作前后加入事务管理 -->
<aop:advisor pointcut-ref="insertPointCut" advice-ref="advice" />
</aop:config>
<!-- 配置事务 -->
<bean id="deptDao" class="dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sFactory" />
</bean>
<bean id="userbiz" class="biz.impl.UserBizImpl" scope="prototype">
<property name="dao" ref="deptDao"></property>
</bean>
<bean id="deptAction" class="action.userAction">
<property name="userbiz" ref="userbiz" />
</bean>
<!-- 报销主表 -->
<bean id="claimVoucherDao" class="dao.impl.BizClaimVoucherDaoImpl">
<property name="sessionFactory" ref="sFactory" />
</bean>
<bean id="claimVoucherBiz" class="biz.impl.BizClaimVoucherBizIMpl">
<property name="cvDao" ref="claimVoucherDao"></property>
</bean>
<bean id="voucherAction" class="action.ClaimVoucherAction" scope="prototype">
<property name="itemsBiz" ref="itemsBiz"></property>
<property name="caimVoucherBiz" ref="claimVoucherBiz"></property>
</bean>
</beans>
#2
#3
private IBizClaimVoucherBiz caimVoucherBiz; 加set方法
#4
private BizClaimVoucher claimVoucher = new BizClaimVoucher();
改成
private BizClaimVoucher claimVoucher;
并加上set方法
改成
private BizClaimVoucher claimVoucher;
并加上set方法
#5
private BizClaimVoucher claimVoucher = new BizClaimVoucher();
是实体类
是实体类
#6
这个是实体类
#7
这个是实体类
#8
java.lang.NullPointerException
at action.ClaimVoucherAction.addClaimVoucher(ClaimVoucherAction.java:101)
看这里
at action.ClaimVoucherAction.addClaimVoucher(ClaimVoucherAction.java:101)
看这里
#9
caimVoucherBiz这个是空的