首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

Exception occurred during processing request: null java.lang.NullPointerExceptio

2014-01-03 
Exception occurred during processing request: null java.lang.NullPointerExceptio@SuppressWarnings(

Exception occurred during processing request: null java.lang.NullPointerExceptio
@SuppressWarnings("serial")
public class RoleAction extends ActionSupport{
private RoleService roleService;
private Yuangong yuanGong;
private List<Yuangong>yuangList = new ArrayList<Yuangong>(0);
private String keyWord;


public RoleService getRoleService() {
return roleService;
}

public void setRoleService(RoleService roleService) {
this.roleService = roleService;
}


public Yuangong getYuanGong() {
return yuanGong;
}

public void setYuanGong(Yuangong yuanGong) {
this.yuanGong = yuanGong;
}

public List<Yuangong> getYuangList() {
return yuangList;
}

public void setYuangList(List<Yuangong> yuangList) {
this.yuangList = yuangList;
}

public String getKeyWord() {
return keyWord;
}

public void setKeyWord(String keyWord) {
this.keyWord = keyWord;
}

/**
 * 添加角色
 * @return
 */
public String addRole(){
Yuangong yg = roleService.insertYG(yuanGong);
if(yg!=null){
return "success";
}
return "input";




public interface RoleService {
public Yuangong insertYG(Yuangong yuanGong);
public Yuangong deleteYG(Yuangong yuanGong);
public Yuangong upateYG(Yuangong yuanGong);
public Yuangong findByYgBH(String ygbh);
public List<Yuangong> findByKeyWord(String keyWord);

}


public class RoleServiceImpl implements RoleService {

private RoleDao roleDao;

public void setRoleDao(RoleDao roleDao) {
this.roleDao = roleDao;
}

@Override
public Yuangong insertYG(Yuangong yuanGong) {

return roleDao.insert(yuanGong);
}



public interface RoleDao {

public Yuangong insert(Yuangong yuanGong);
public Yuangong update(Yuangong yuanGong);
public Yuangong delete(Yuangong yuanGong);
public Yuangong findByYgBH(String ygbh);
public List<Yuangong> findByKeyWord(String keyWord);



}


public class RoleDaoImpl implements RoleDao {

/**
 * 插入员工信息
 * @param yuanGong
 * @return
 */
@SuppressWarnings("unused")
@Override
public Yuangong insert(Yuangong yuanGong) {

//创建连接对象
DBMangger dbMangger = new DBMangger();
//SQL语句
String sql = "insert into YuanGong values("+yuanGong.getYgbh()+","+yuanGong.getYgxm()+"," +
""+yuanGong.getYgzh()+","+yuanGong.getYgmm()+","+yuanGong.getYgmm()+","
+yuanGong.getBmbh()+","+yuanGong.getStatus()+",sysdate)";

int i = dbMangger.executeUpdate(sql);
if(i>0){
System.out.println("执行成功");
return yuanGong;
}else{
System.out.println("保存失败");
return null;
}


}




[解决办法]

引用:
Quote: 引用:

roleService = new roleServiceImpl();
这点 没看懂 亲


public void setRoleService(RoleService roleService) {
this.roleService = new roleServiceImpl();
}

或是 private RoleService roleService = new roleService();
 private RoleDao roleDao = new roleDao();
用这种把
在set方法上还要去掉set方法麻烦


[解决办法]
引用:
Quote: 引用:

是把你原来RoleDaoImpl 类里的改成private RoleDao roleDao = new roleDaoImpl();

。,。。。。大哥我太笨了 没懂起, 类怎么改成这个呀


你可以自己想想你这个为什么会是为空啊,肯定是你没给他实例化,你调用roleService.insertYG(yuanGong);
的时候roleService为空,roleService有实例?你没付给他,需要new 一个roleServiceImpl(),roleServiceImpl中掉insertYG(。。)的时候需要dao,同样这里的dao也没有对应实例化是空的,你需要给他dao的实现

热点排行