2014年1月2日星期四

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

@ SuppressWarnings ("serial")
public class RoleAction extends ActionSupport {
private RoleService roleService;
private Yuangong yuanGong;
private List yuangList = new ArrayList (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 getYuangList () {
return yuangList;
}

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

public String getKeyWord () {
return keyWord;
}

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

/ **
* Add Roles
* @ 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 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 findByKeyWord (String keyWord);



}


public class RoleDaoImpl implements RoleDao {

/ **
* insert employee information
* @ param yuanGong
* @ return
* /
@ SuppressWarnings ("unused")
@ Override
public Yuangong insert (Yuangong yuanGong) {

/ / Create a connection object
DBMangger dbMangger = new DBMangger ();
/ / SQL statement
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 (" executed successfully " ) ;
return yuanGong;
} else {
System.out.println (" Save failed" ) ;
return null;
}


}




------ Solution ------------------------------------ --------
this point did not understand the pro-  

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

or private RoleService roleService = new roleService ();
private RoleDao roleDao = new roleDao ();
use this to
On the set method set methods also remove troublesome


------ Solution ------------------------------------ --------

. . . . . Big Brother did not know I was awkward since changed the way the class how  

Why do you think you can own this would be empty , ah, you certainly did not give him instantiated, you call roleService.insertYG (yuanGong);
when roleService is empty , roleService have examples ? You did not pay him , needs new one roleServiceImpl (), roleServiceImpl in off insertYG (..) When the need dao, same here, did not correspond to instantiate dao is empty, you need to give him the realization dao
------ For reference only ---------------------------------------
landlord, the error message does, there 's the line of code error
------ For reference only ------------------------- --------------


严重: Exception occurred during processing request: null
java.lang.NullPointerException
at com.sles.train.action.RoleAction.addRole(RoleAction.java:67)
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:446)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:285)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)

------ For reference only ----------------------------------- ----
Exception occurred during processing request: null
at com.sles.train.action.RoleAction.addRole (RoleAction.java: 67)
------ For reference only -------------- -------------------------
debug debugging see the emergence null .
------ For reference only -------------------------------------- -

Yeah , I was wrong or how to write Yeah , I put the code involved are posted out of
------ For reference only - -------------------------------------

debugging directly in that big break points , but do not continue to have a value of
------ For reference only ------------------------- --------------
Yuangong yg = roleService.insertYG(yuanGong);

two possibilities:
1 roleService is empty
2 yuanGong passed to it is empty, but the parameter values ​​must be non-null value insertYG
landlord and then check the next
------ For reference only ------------------------------ ---------
Yuangong yg = roleService.insertYG (yuanGong);

roleService not have a value . yuanGong not have value ?

dbMangger.executeUpdate (sql); facie sql do not
------ For reference only ------------------? ---------------------
sql writing I was able to directly test the
------ For reference only ---------------------------------------
roleService is null ; but why would it be null
------ For reference only --------------------------- ------------
sql writing I was able to directly test the   roleService empty
------ For reference only ------------------------------- --------
roleService configuration file did not inject come .
------ For reference only -------------------------------------- -
use srping to inject ? I just used to write strtus then divided dao service action
------ For reference only --------------- ------------------------
roleService = new roleServiceImpl ();
------ For reference only ---------------------------------------
this point did not understand ; the pro
------ For reference only ------------------------------------ ---
RoleServiceImpl the private RoleDao roleDao; 's set method to roleDao = new roleDaoImpl ();
------ For reference only - -------------------------------------
service is not injected , there is no new ; that is null it. give a similar look
------ For reference only --- ------------------------------------
this point did not understand the pro-          
  
public void setRoleService (RoleService roleService) {   
this.roleService = new roleServiceImpl ();   
}   
  
or private RoleService roleService = new roleService ();   
private RoleDao roleDao = new roleDao ();   
use this to   
On the set method set methods also remove troublesome   
  
 

wrong private RoleService roleService = new roleServiceImpl ();
private RoleDao roleDao = new roleDaoImpl ();
------ For reference only ----------------- ----------------------
this point did not understand the pro-                
    
public void setRoleService (RoleService roleService) {     
this.roleService = new roleServiceImpl ();     
}     
    
or private RoleService roleService = new roleService ();     
private RoleDao roleDao = new roleDao ();     
use this to     
On the set method set methods also remove troublesome     
    
         
  
wrong private RoleService roleService = new roleServiceImpl ();   
private RoleDao roleDao = new roleDaoImpl ();  

Do you mean in action here private RoleDao roleDao = new roleDaoImpl ()
but this is useless to service this layer Yeah
------ For reference only ------------------------ ---------------
is to your original RoleDaoImpl class changed to private RoleDao roleDao = new roleDaoImpl ();
--- --- For reference only ---------------------------------------

. . . . . Big Brother did not know I was awkward since changed the way the class how
------ For reference only ------------------- --------------------
ah this injected with a spring in my useless spring and hibernate
------ For reference only ------------------------------------- -
not inject their own new one.
------ For reference only -------------------------------------- -
you said my ideas about NEW opened . Really thank
------ For reference only ------------------------------ ---------

. . . . . Big Brother did not know I was awkward since changed the way the class how          
  
Why do you think you can own this would be empty , ah, you certainly did not give him instantiated, you call roleService.insertYG (yuanGong);   
when roleService is empty , roleService have examples ? You did not pay him , needs new one roleServiceImpl (), roleServiceImpl in off insertYG (..) When the need dao, same here, did not correspond to instantiate dao is empty, you need to give him the realization of dao   I got a thank you, all of a sudden the word NEW really put my thoughts turned really thank ah
------ For reference only ---------------------------------------
should be solved

没有评论:

发表评论