当前位置: 代码迷 >> Java Web开发 >> struts1 nullpointerexception解决思路
  详细解决方案

struts1 nullpointerexception解决思路

热度:9586   发布时间:2016-04-10 22:56:10.0
struts1 nullpointerexception

exception 

javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:805)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

java.lang.NullPointerException
org.apache.commons.beanutils.PropertyUtilsBean.setIndexedProperty(PropertyUtilsBean.java:1414)
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1016)
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:805)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)






actionForm类 
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.xsm.struts.form;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/** 
 * MyEclipse Struts
 * Creation date: 01-04-2011
 * 
 * XDoclet definition:
 * @struts.form name="subject_lib_showForm"
 */
public class Subject_lib_showForm extends ActionForm {


/** id property */
private int subject_id;
private String subject_name;
private String answer_a;
private String answer_b;
private String answer_c;
private String answer_d;
private  int[] idArrS;//记录单选题的试题ID属性
private String[] answerArrS;//在显示试题和提交试卷时 记录单选题答案的属性



/** 
 * Method validate
 * @param mapping
 * @param request
 * @return ActionErrors
 */
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}

/** 
 * Method reset
 * @param mapping
 * @param request
 */
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}

/** 
 * Returns the id.
 * @return String
 */

public String getAnswer_a() {
return answer_a;
}

public void setAnswer_a(String answer_a) {
this.answer_a = answer_a;
}

public String getAnswer_b() {
return answer_b;
}

public void setAnswer_b(String answer_b) {
this.answer_b = answer_b;
}

public String getAnswer_c() {
return answer_c;
}

public void setAnswer_c(String answer_c) {
this.answer_c = answer_c;
}

public String getAnswer_d() {
return answer_d;
}

public void setAnswer_d(String answer_d) {
this.answer_d = answer_d;
}

public int getSubject_id() {
return subject_id;
}

public void setSubject_id(int subject_id) {
this.subject_id = subject_id;
}

public String getSubject_name() {
return subject_name;
}

public void setSubject_name(String subject_name) {
this.subject_name = subject_name;
}

public String[] getAnswerArrS() {
return answerArrS;
}

public void setAnswerArrS(String[] answerArrS) {
this.answerArrS = answerArrS;
}

public int[] getIdArrS() {
return idArrS;
}

public void setIdArrS(int[] idArrS) {
this.idArrS = idArrS;
}
public void setSize(int size){
answerArrS=new String[size];
idArrS=new int[size];
System.out.println("单选题的数组大小:"+answerArrS.length);
}

}

可能是idArrS和answerArrS这2个数组出问题?
下面上Action.

public ActionForward execute(ActionMapping mapping, ActionForm form,
  相关解决方案