wood burning stoves 2.0
The moose likes Struts and the fly likes NullPointer Exception in Executing a Struts Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "NullPointer Exception in Executing a Struts Program" Watch "NullPointer Exception in Executing a Struts Program" New topic

NullPointer Exception in Executing a Struts Program

Kasiraj Murugesa pandian

Joined: Sep 09, 2011
Posts: 21

Hi All ,
I am just done writing my first Struts Web Application without any compilations errors . Anyhow while trying to execute i get a runtime Exception during validation part . Kindly tell me where i went wrong and what changes need to be made .

Here are the following Exceptions and codings that i wrote in Netbeans:


WARNING: Unhandled Exception thrown: class java.lang.NullPointerException
WARNING: StandardWrapperValve[action]: PWC1406: Servlet.service() for servlet action threw exception
at com.LoginAction.execute(LoginAction.java:38)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)




<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"

<form-bean name="LoginActionForm" type="com.LoginActionForm"/>




<forward name="welcome" path="/Welcome.do"/>

<action input="/welcomeStruts.jsp" name="LoginActionForm" path="/*" scope="request" type="com.LoginAction"/>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>

<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

<message-resources parameter="com/myapp/struts/ApplicationResource"/>

<!-- ========================= Tiles plugin ===============================-->
This plugin initialize Tiles definition factory. This later can takes some
parameters explained here after. The plugin first read parameters from
web.xml, thenoverload them with parameters defined here. All parameters
are optional.
The plugin should be declared in each struts-config file.
- definitions-config: (optional)
Specify configuration file names. There can be several comma
separated file names (default: ?? )
- moduleAware: (optional - struts1.1)
Specify if the Tiles definition factory is module aware. If true
(default), there will be one factory for each Struts module.
If false, there will be one common factory for all module. In this
later case, it is still needed to declare one plugin per module.
The factory will be initialized with parameters found in the first
initialized plugin (generally the one associated with the default
true : One factory per module. (default)
false : one single shared factory for all modules
- definitions-parser-validate: (optional)
Specify if xml parser should validate the Tiles configuration file.
true : validate. DTD should be specified in file header (default)
false : no validation

Paths found in Tiles definitions are relative to the main context.
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">


When i execute this program , after clicking the OK button for Authentication it encounters an exception .

Kindly tell me what changes i need to make to let the program execute Successfully.

Thanks in Advance .

Joe Ess

Joined: Oct 29, 2001
Posts: 9150

Your exception originates at line 38 in LoginAction:

but the code you showed us does not have 38 lines. My wild guess is that the problem is on this line:

One way to avoid null pointer exceptions when comparing Strings is to use the literal String as the first object in the comparison. That way you will never get a NPE:

[How To Ask Questions On JavaRanch]
Kasiraj Murugesa pandian

Joined: Sep 09, 2011
Posts: 21

Joe Ess wrote:Your exception originates at line 38 in LoginAction:

but the code you showed us does not have 38 lines. My wild guess is that the problem is on this line:

One way to avoid null pointer exceptions when comparing Strings is to use the literal String as the first object in the comparison. That way you will never get a NPE:

Sorry about the Line Numbers since they may not be in proper order as i have removed some comment line .

I tried the same thing and it worked Fine after i did the program right from the scratch again

but the actual main problem that i noticed was , i haven't given the url path correctly while creating a New Action Struts in Netbeans . That is where i made the mistake . Just Now i got it rectified .

Anyways thank you very much for your Valuable information on using the String comparison in other way.

Thanks Again

I agree. Here's the link: http://aspose.com/file-tools
subject: NullPointer Exception in Executing a Struts Program
It's not a secret anymore!