wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Null PointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Null PointerException" Watch "Null PointerException" New topic
Author

Null PointerException

daisy patrick
Greenhorn

Joined: Apr 24, 2005
Posts: 3
Hi All
I have developed an applicatoin on struts..
in which..
The action class performs a lookup on the session bean
but lookup is not succesful and throws exception..
i ma working on wsad 5.0..and i have kept the files in the related folders...
and i am sure i'm not missing any references..if some body can help me out ..i wud be greatful
the code is as follows..

this is the action class:

package com.ibm.sample.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import common.LogIn;
import common.LogInHome;

import javax.naming.*;
import javax.ejb.*;
import java.rmi.RemoteException;
import javax.rmi.*;



/**
* @version 1.0
* @author
*/
public class LogSubmitAction extends Action {

/**
* Constructor
*/
public LogSubmitAction() {

super();

}
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {

ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
// return value
com.ibm.sample.struts.LogSubmitForm logSubmitForm =
(com.ibm.sample.struts.LogSubmitForm) form;
String name = null;

String pwd= null;
LogInHome logInBeanHome = null;
LogIn logIn = null;
InitialContext initContext = null;
System.out.println("in the action class");
final String JNDIName = "ejb/common/LogInHome";
boolean result=false;






try {
name = logSubmitForm.getName();
System.out.println("name is"+name);
pwd=logSubmitForm.getPassword();
System.out.println("password is"+pwd);
request.setAttribute("name",name);
request.setAttribute("pwd",pwd);

try {
System.out.println("Performing the lookup..");
Object obj = initContext.lookup("/ejb/common/LogInBeanHome");
System.out.println("got thee obj");
logInBeanHome = (LogInHome)
PortableRemoteObject.narrow(obj,
LogInHome.class);
System.out.println("lookup performed");
}
catch (Exception e) {
System.err.println("Whoops! Error retrieving the home interface: " + e);
e.printStackTrace();
}
logIn = logInBeanHome.create();
System.out.println("home cerated");


result=logIn.getLogInDataResult(logSubmitForm.getName(),logSubmitForm.getPassword());
System.out.println("retrieved the data");

// do something here

} catch (Exception e) {

System.err.println("Whoops! Exception creating new HelloWorldSession: " + e);
e.printStackTrace();
// Report the error using the appropriate name and ID.
errors.add("name", new ActionError("id"));

}

// If a message is required, save the specified key(s)
// into the request for use by the <struts:errors> tag.

if (!errors.empty()) {
saveErrors(request, errors);
}
// Write logic determining how the user should be forwarded.


if(result== true)
forward=mapping.findForward("success");
else
forward=mapping.findForward("failure");
return(forward);







}
}




and this is the session bean classes:


package common;




/**
* Home interface for Enterprise Bean: LogIn
*/
public interface LogInHome extends javax.ejb.EJBHome {
/**
* Creates a default instance of Session Bean: LogIn
*/
public common.LogIn create()
throws javax.ejb.CreateException, java.rmi.RemoteException;
}




package common;
import javax.naming.*;
import java.lang.*;
import javax.ejb.*;
import java.rmi.RemoteException;
import dao.LogInDAO;
/**
* Bean implementation class for Enterprise Bean: LogIn
*/
public class LogInBean implements javax.ejb.SessionBean {
private javax.ejb.SessionContext mySessionCtx;
/**
* getSessionContext
*/
public javax.ejb.SessionContext getSessionContext() {
return mySessionCtx;
}
/**
* setSessionContext
*/
public void setSessionContext(javax.ejb.SessionContext ctx) {
mySessionCtx = ctx;
}
/**
* ejbCreate
*/
public void ejbCreate() throws javax.ejb.CreateException {
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() {
}



public boolean getLogInDataResult(String u_name,String u_pwd) throws Exception
{
String s1=null;
try
{
s1=LogInDAO.getUserPassword(u_name);

}
catch(Exception e)
{
System.out.println("error from login bean");
}
if(u_pwd==s1)
return(true);
else
return(false);

return(true);

}





package common;
/**
* Remote interface for Enterprise Bean: LogIn
*/
public interface LogIn extends javax.ejb.EJBObject {
public boolean getLogInDataResult(String u_name,String u_pwd) throws Exception;
}

}














and the exception i'm gettin gi is



[4/26/05 13:27:53:389 EDT] 2a7ee4a5 SystemOut O Performing the lookup..
[4/26/05 13:27:53:389 EDT] 2a7ee4a5 SystemErr R Whoops! Error retrieving the home interface: java.lang.NullPointerException
[4/26/05 13:27:53:399 EDT] 2a7ee4a5 SystemErr R java.lang.NullPointerException
[4/26/05 13:27:53:469 EDT] 2a7ee4a5 SystemErr R at com.ibm.sample.struts.LogSubmitAction.execute(LogSubmitAction.java:73)
[4/26/05 13:27:53:469 EDT] 2a7ee4a5 SystemErr R at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:446)
[4/26/05 13:27:53:469 EDT] 2a7ee4a5 SystemErr R at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266)
[4/26/05 13:27:53:529 EDT] 2a7ee4a5 SystemErr R at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
[4/26/05 13:27:53:529 EDT] 2a7ee4a5 SystemErr R at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
[4/26/05 13:27:53:529 EDT] 2a7ee4a5 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
[4/26/05 13:27:53:529 EDT] 2a7ee4a5 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[4/26/05 13:27:53:529 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
[4/26/05 13:27:53:529 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
[4/26/05 13:27:53:529 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
[4/26/05 13:27:53:529 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
[4/26/05 13:27:53:529 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:258)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:872)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:491)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:173)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:199)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:331)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:432)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:343)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:592)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R Whoops! Exception creating new HelloWorldSession: java.lang.NullPointerException
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R java.lang.NullPointerException
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.sample.struts.LogSubmitAction.execute(LogSubmitAction.java:84)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:446)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
[4/26/05 13:27:53:539 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:258)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:872)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:491)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:173)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:199)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:331)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:432)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:343)
[4/26/05 13:27:53:549 EDT] 2a7ee4a5 SystemErr R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:592)



1)even i tried using java:comp/env
2)and tried to just perform a lookup on the same session bean without using the dao



i wud be thankful if somebody can help me out
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null PointerException
 
Similar Threads
WebSphere V5 CMP create problem
Problem with Last Participant Support in WebSphere 5.1?
WSAD DataSource Connection Exception
Invalid XML error...Newbie question
login error using WSAD5.1 & Oracle