review your java >speaking of which >did the op display the source for ResourceBundleMessageSource.java? >Martin
> Date: Wed, 19 Aug 2009 09:34:48 -0700 > From: tommy...@yahoo.com > Subject: Re: Hibernate3+Spring2.5+Struts2 > To: user@struts.apache.org > > > > > > > ----- Original Message ---- > > From: ZiedBejaoui <bejaouiz...@hotmail.com> > > To: Struts Users Mailing List <user@struts.apache.org> > > Sent: Wednesday, August 19, 2009 9:23:35 AM > > Subject: Re: Hibernate3+Spring2.5+Struts2 > > > > Thanks for your reply however I didn't get you point, I have created a > > userserviceImp instance in my loginaction. > > could you please tell what you mean? > > > > >> >> > > >> >> public class LoginAction extends ActionSupport { > > >> >> > > >> >> private UserServiceImp userService; > > >> >> private String message; > > >> >> private String username; > > >> >> private String password; > > >> >> private ResourceBundleMessageSource messageSource; > > >> >> > > >> >> public LoginAction() { > > >> >> } > > >> >> > > >> >> @Override > > >> >> public String execute() throws Exception { > > >> >> User usr = userService.getUser(username); > > >> >> if(usr != null){ > > >> >> if(usr.getPassword().equals(password)){ > > >> >> message = messageSource.getMessage("loginSuccess", > > >> > null,Locale.CHINA); > > >> >> }else{ > > >> >> message = messageSource.getMessage("pswError", > > >> > null,Locale.CHINA); > > >> >> } > > >> >> }else{ > > >> >> message = messageSource.getMessage("usrError", > > >> > null,Locale.CHINA); > > >> >> } > > >> >> return SUCCESS; > > >> >> } > > >> >> > > >> >> public void setUserService(UserServiceImp userService) { > > >> >> this.userService = userService; > > >> >> } > > >> >> > > >> >> public String getMessage() { > > >> >> return message; > > >> >> } > > >> >> > > >> >> public void setMessage(String message) { > > >> >> this.message = message; > > >> >> } > > >> >> > > >> >> public String getUsername() { > > >> >> return username; > > >> >> } > > >> >> > > >> >> public void setUsername(String username) { > > >> >> this.username = username; > > >> >> } > > >> >> > > >> >> public String getPassword() { > > >> >> return password; > > >> >> } > > >> >> > > >> >> public void setPassword(String password) { > > >> >> this.password = password; > > >> >> } > > >> >> > > >> >> public void setMessageSource(ResourceBundleMessageSource > > >> >> messageSource) > > >> > { > > >> >> this.messageSource = messageSource; > > >> >> } > > >> >> > > >> >> } > > >> >> > > > > > > > > > > > > Your UserServiceImp userService was instantiated but never initialized in > > > your LoginAction class. Hence the NPE. When you to execute a method > > > that > > > does not a reference to real object, you'll get NPE. You might want to > > > review your java :) > > > > > > Best regards, > > > Tommy > > > > > In many programming languages, all variables (fields) have to be initialized > before use with exception of primitive types (byte, short, etc - NOTE: String > is null by default- they will have a default value). Your custom class > UserServiceImp was instantiated with userService but never initialized. So > when you try to do userService.getUser() in the execute() method of your > LoginAction, you'll get the NPE as seen. I suggest you spend some time and go > through this http://java.sun.com/docs/books/tutorial/ . Your current problem > is covered here: > http://java.sun.com/docs/books/tutorial/java/javaOO/objectcreation.html > > Best regards, > Tommy > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > _________________________________________________________________ Windows Live: Keep your friends up to date with what you do online. http://windowslive.com/Campaign/SocialNetworking?ocid=PID23285::T:WLMTAGL:ON:WL:en-US:SI_SB_online:082009