java.lang.NullPointerException
action
// 添加用户
public String addUser() {
this.test4id.setName(name);
this.test4id.setOperatorId(operatorid);
this.test4id.setPassword(password);
this.test4id.setStatus(status);
this.test4.setId(this.getTest4id());
this.getUserService().saveUser(this.getTest4());
return "list";
}test4
package com.t.bean;/**
 * Test4 entity.
 * 
 * @author MyEclipse Persistence Tools
 */public class Test4 implements java.io.Serializable { // Fields private Test4Id id; // Constructors /** default constructor */
public Test4() {
} /** full constructor */
public Test4(Test4Id id) {
this.id = id;
} // Property accessors public Test4Id getId() {
return this.id;
} public void setId(Test4Id id) {
this.id = id;
}}Test4Idpackage com.t.bean;/**
 * Test4Id entity.
 * 
 * @author MyEclipse Persistence Tools
 */public class Test4Id implements java.io.Serializable { // Fields private Long operatorId;
private String name;
private String password;
private Long status; // Constructors /** default constructor */
public Test4Id() {
} /** minimal constructor */
public Test4Id(Long operatorId) {
this.operatorId = operatorId;
} /** full constructor */
public Test4Id(Long operatorId, String name, String password, Long status) {
this.operatorId = operatorId;
this.name = name;
this.password = password;
this.status = status;
} // Property accessors public Long getOperatorId() {
return this.operatorId;
} public void setOperatorId(Long operatorId) {
this.operatorId = operatorId;
} public String getName() {
return this.name;
} public void setName(String name) {
this.name = name;
} public String getPassword() {
return this.password;
} public void setPassword(String password) {
this.password = password;
} public Long getStatus() {
return this.status;
} public void setStatus(Long status) {
this.status = status;
} public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof Test4Id))
return false;
Test4Id castOther = (Test4Id) other; return ((this.getOperatorId() == castOther.getOperatorId()) || (this
.getOperatorId() != null
&& castOther.getOperatorId() != null && this.getOperatorId()
.equals(castOther.getOperatorId())))
&& ((this.getName() == castOther.getName()) || (this.getName() != null
&& castOther.getName() != null && this.getName()
.equals(castOther.getName())))
&& ((this.getPassword() == castOther.getPassword()) || (this
.getPassword() != null
&& castOther.getPassword() != null && this
.getPassword().equals(castOther.getPassword())))
&& ((this.getStatus() == castOther.getStatus()) || (this
.getStatus() != null
&& castOther.getStatus() != null && this.getStatus()
.equals(castOther.getStatus())));
} public int hashCode() {
int result = 17; result = 37
* result
+ (getOperatorId() == null ? 0 : this.getOperatorId()
.hashCode());
result = 37 * result
+ (getName() == null ? 0 : this.getName().hashCode());
result = 37 * result
+ (getPassword() == null ? 0 : this.getPassword().hashCode());
result = 37 * result
+ (getStatus() == null ? 0 : this.getStatus().hashCode());
return result;
}}

解决方案 »

  1.   

    后面两个hibernate自动生成的类
    还有个mapping文件。
    可以忽略,主要看前面,action中的那个方法,报错
      

  2.   

    this.test4.setId(this.getTest4id());
      

  3.   

    你不是说得很清楚了吗空指针异常吗你要检查那个对象是空的丫java的报错都是很精确的
      

  4.   

    说明这个对象没有被实例test4id ,action中设置这个对象的get方法了么