You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Paul Goepfert <pa...@gmail.com> on 2005/06/05 01:55:21 UTC
NullPointerException problem
I have written a few java files and rewrote a template to be more like a
template rather then standard html. When I tried to view the webpage I
found that I have a NullPointerException. Usually when there is a NPE
the compiler tells me where in my code the NPE is coming from. However
it just starts out with
"org.apache.velocity.tools.struts.StrutsUtils.getMessageResources(StrutsUtils.java:211)"
I think the problem is that the properties file I defined is not moved
to the classes directory when the javacode is compiled. How do I do
that if I am using Ant to compiule my source code? However when I did
move the properties file into the right directory, I still get the same
error. Oh yeah this happens on all velocity pages that I created
before I changed the code.
If you need to see the entire error please let me know and I will
provide it.
Paul
If you need to see
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: NullPointerException problem
Posted by Paul Goepfert <pa...@gmail.com>.
Here is the complete error I get when I try to view the vm template in a
web browser.
VelocityViewServlet : Error processing the template
java.lang.NullPointerException
at org.apache.velocity.tools.struts.StrutsUtils.getMessageResources(StrutsUtils.java:211)
at org.apache.velocity.tools.struts.MessageResourcesTool.init(MessageResourcesTool.java:59)
at org.apache.velocity.tools.view.ViewToolInfo.getInstance(ViewToolInfo.java:133)
at org.apache.velocity.tools.view.servlet.ServletToolboxManager.getToolboxContext(ServletToolboxManager.java:354)
at org.apache.velocity.tools.view.servlet.VelocityViewServlet.createContext(VelocityViewServlet.java:519)
at org.apache.velocity.tools.view.servlet.VelocityViewServlet.doRequest(VelocityViewServlet.java:401)
at org.apache.velocity.tools.view.servlet.VelocityViewServlet.doGet(VelocityViewServlet.java:373)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:534)
I am not sure how much of my code I should give. I have a bean java
file, a form java file, and a action java file. I also have a web.xml
and a strukts-config file. I thinkk youu would need all that to
prooduce myy error. So tell me what you think you would need to see
and I'll post it.
Paul
Shinobu Kawai wrote:
>Hi Paul,
>
>
>
>>I have written a few java files and rewrote a template to be more like a
>>template rather then standard html. When I tried to view the webpage I
>>found that I have a NullPointerException. Usually when there is a NPE
>>the compiler tells me where in my code the NPE is coming from. However
>>it just starts out with
>>"org.apache.velocity.tools.struts.StrutsUtils.getMessageResources(StrutsUtils.java:211)"
>>
>>
>
>Source says, you didn't give it a ServletContext, or a ModuleConfig
>could not be found.
> return (MessageResources)app.getAttribute(Globals.MESSAGES_KEY +
> moduleConfig.getPrefix());
>
>
>
>>I think the problem is that the properties file I defined is not moved
>>to the classes directory when the javacode is compiled. How do I do
>>that if I am using Ant to compiule my source code? However when I did
>>move the properties file into the right directory, I still get the same
>>error. Oh yeah this happens on all velocity pages that I created
>>before I changed the code.
>>
>>If you need to see the entire error please let me know and I will
>>provide it.
>>
>>
>
>I think it would. Better yet, you could show us some minimal code to
>reproduce your problem. ;)
>
>As for the Ant question, the Ant User List would be a better place to ask.
> http://ant.apache.org/mail.html
>
>Best regards,
>-- Shinobu
>
>--
>Shinobu Kawai <sh...@gmail.com>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: NullPointerException problem
Posted by Paul Goepfert <pa...@gmail.com>.
Holy Cow I can't believe that the problem was just that. The wrong file
name for the struts configuration file. Now all I have is a small
problem with getting the $text.get(property) to display the text rather
then the code. The warning that I get is template = /info.vm [line
42,column 74] : $text.get("done") is not a valid reference.
Again thanks for the help
-Paul
Shinobu Kawai wrote:
>Hi Paul,
>
>
>
>>I just checked both my web.xml and struts-conf.xml. They both look fine
>>to me but then again this is the first time I am developing a web
>>program. I mighht not know the correct syntax. However I am pretty
>>sure that my web.xml and struts-config.xml are correct.
>>
>>Is there anything missing from my struts-config.xml file or my web.xml
>>file that would make my webpage throw the NullPointerException?
>>
>>Here is an updated version of my struts-config.xml and web.xml files
>>
>>
>
>AFAICT, these two don't mix.
>
>
>
>>________________
>>struts-conf.xml
>>________________
>>
>>
>
>## snip
>
>
>
>>_________
>>web.xml
>>_________
>>
>>
>
>## snip
>
>
>
>> <init-param>
>> <param-name>config</param-name>
>> <param-value>/WEB-INF/conf/struts-config.xml</param-value>
>> </init-param>
>>
>>
>
>Are you sure that the Struts part is working?
>
>Best regards,
>-- Shinobu
>
>--
>Shinobu Kawai <sh...@gmail.com>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: NullPointerException problem
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Paul,
> I just checked both my web.xml and struts-conf.xml. They both look fine
> to me but then again this is the first time I am developing a web
> program. I mighht not know the correct syntax. However I am pretty
> sure that my web.xml and struts-config.xml are correct.
>
> Is there anything missing from my struts-config.xml file or my web.xml
> file that would make my webpage throw the NullPointerException?
>
> Here is an updated version of my struts-config.xml and web.xml files
AFAICT, these two don't mix.
> ________________
> struts-conf.xml
> ________________
## snip
> _________
> web.xml
> _________
## snip
> <init-param>
> <param-name>config</param-name>
> <param-value>/WEB-INF/conf/struts-config.xml</param-value>
> </init-param>
Are you sure that the Struts part is working?
Best regards,
-- Shinobu
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: NullPointerException problem
Posted by Paul Goepfert <pa...@gmail.com>.
I just checked both my web.xml and struts-conf.xml. They both look fine
to me but then again this is the first time I am developing a web
program. I mighht not know the correct syntax. However I am pretty
sure that my web.xml and struts-config.xml are correct.
Is there anything missing from my struts-config.xml file or my web.xml
file that would make my webpage throw the NullPointerException?
Here is an updated version of my struts-config.xml and web.xml files
-Paul
________________
struts-conf.xml
________________
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="infoForm" type="forms.InfoForm" />
<form-bean name="menuForm" type="forms.MenuForm" />
</form-beans>
<action-mappings>
<action path="/Info"
type="actions.InfoAction"
name="infoForm"
scope="request">
<forward name="Enter Information"
path="/Web Pages/info.vm"/>
<forward name="done"
path="/Web Pages/menu.vm"/>
</action>
<action path="/Menu"
type="actions.MenuAction"
name="menuForm"
scope="request">
<forward name="enterInfo"
path="/Web Pages/info.vm" />
<forward name="default"
path="/Web Pages/results.vm" />
<forward name="sort"
path="/Web Pages/sort.vm" />
</action>
</action-mappings>
<message-resources parameter="ApplicationResources" />
</struts-config>
_________
web.xml
_________
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/conf/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>velocity</servlet-name>
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/conf/toolbox.xml</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>info.vm</welcome-file>
</welcome-file-list>
</web-app>
Shinobu Kawai wrote:
>Hi Paul,
>
>
>
>>Here is the Action.java Velocity template and the properties file. If
>>anyone want's more send me your email address and I'll send you a copy
>>of it. I don't want my entire code on the web.
>>
>>
>
>Ok, I have a feeling that your Struts is not loaded correctly. Can
>you check your configuration files and see if they are correct? In
>your original postings, they were not even in xml format. :(
>- web.xml
>- struts-config.xml
>
>Best regards,
>-- Shinobu
>
>--
>Shinobu Kawai <sh...@gmail.com>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: NullPointerException problem
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Paul,
> Here is the Action.java Velocity template and the properties file. If
> anyone want's more send me your email address and I'll send you a copy
> of it. I don't want my entire code on the web.
Ok, I have a feeling that your Struts is not loaded correctly. Can
you check your configuration files and see if they are correct? In
your original postings, they were not even in xml format. :(
- web.xml
- struts-config.xml
Best regards,
-- Shinobu
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: NullPointerException problem
Posted by Paul Goepfert <pa...@gmail.com>.
Here is the Action.java Velocity template and the properties file. If
anyone want's more send me your email address and I'll send you a copy
of it. I don't want my entire code on the web.
_______________________________
InfoAction.java
_______________________________
package actions;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import beans.*;
import logic.*;
import forms.*;
public class InfoAction extends Action
{
public ActionForward execute (ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String action;
HttpSession session;
DB database = new DB ();
try
{
session = request.getSession();
action = ((InfoForm)form).getAction();
if(action.equals("Enter Information"))
{
InfoBean bean = (InfoBean)session.getAttribute("info");
if(bean == null)
{
bean = new InfoBean ();
session.setAttribute("info", bean);
}
bean.setFirst(((InfoForm)form).getFirst());
bean.setLast(((InfoForm)form).getLast());
bean.setStreet(((InfoForm)form).getStreet());
bean.setCity(((InfoForm)form).getCity());
bean.setState(((InfoForm)form).getState());
bean.setZip(((InfoForm)form).getZip());
database.insert(bean);
return (mapping.findForward("Enter Information"));
}
else
{
return (mapping.findForward("done"));
}
}
catch (Exception e)
{
e.printStackTrace();
}
return (mapping.findForward("done"));
}
}
_________________________
info.vm
______________________
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
#* velocity document *#
<html>
<head>
<title>$title.get("title")</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<h1>Personal Information</h1>
<form name="info" action="$link.setAction("Info")" method="get">
<input type="hidden" name="action" value="list">
<table width="263" border="0" align="center">
<tr>
<td>$text.get("first")</td>
<td><input type="text" name="first" value="$!info.first"></td>
</tr>
<tr>
<td>$text.get("last")</td>
<td><input type="text" name="last" value="$!info.last"></td>
</tr>
<tr>
<td>$text.get("street")</td>
<td><input type="text" name="street" value="$!info.street"></td>
</tr>
<tr>
<td>$text.get("city")</td>
<td><input type="text" name="city" value="$!info.city"></td>
</tr>
<tr>
<td>$text.get("state")</td>
<td><input type="text" name="state" value="$!info.state" size="2" maxlength="2" ></td>
</tr>
<tr>
<td>$text.get("zip")</td>
<td><input type="text" name="zip" value="$!info.zip" size="5" maxlength="5"></td>
</tr>
</table>
<input type="submit" name="Submit" value=" $text.get("enter") " onclick="info.action.value='Enter Information'; document.info.submit(); return false;">
<input type="submit" name="Submit2" value=" $text.get("done") " onclick="info.action.value='done'; document.info.submit(); return false;">
</form>
<p> </p>
</div>
</body>
</html>
_______________________________________
ApplicationResources.properties
__________________________________
# Sample ResourceBundle properties file
title=Gathering Personal Information
first=First Name
last=Last Namestreet=Street Address
city=City
state=State
zip=Zip
enter=Enter Information
done=Done
Paul
Shinobu Kawai wrote:
>Hi Paul,
>
>
>
>>I have written a few java files and rewrote a template to be more like a
>>template rather then standard html. When I tried to view the webpage I
>>found that I have a NullPointerException. Usually when there is a NPE
>>the compiler tells me where in my code the NPE is coming from. However
>>it just starts out with
>>"org.apache.velocity.tools.struts.StrutsUtils.getMessageResources(StrutsUtils.java:211)"
>>
>>
>
>Source says, you didn't give it a ServletContext, or a ModuleConfig
>could not be found.
> return (MessageResources)app.getAttribute(Globals.MESSAGES_KEY +
> moduleConfig.getPrefix());
>
>
>
>>I think the problem is that the properties file I defined is not moved
>>to the classes directory when the javacode is compiled. How do I do
>>that if I am using Ant to compiule my source code? However when I did
>>move the properties file into the right directory, I still get the same
>>error. Oh yeah this happens on all velocity pages that I created
>>before I changed the code.
>>
>>If you need to see the entire error please let me know and I will
>>provide it.
>>
>>
>
>I think it would. Better yet, you could show us some minimal code to
>reproduce your problem. ;)
>
>As for the Ant question, the Ant User List would be a better place to ask.
> http://ant.apache.org/mail.html
>
>Best regards,
>-- Shinobu
>
>--
>Shinobu Kawai <sh...@gmail.com>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: NullPointerException problem
Posted by Paul Goepfert <pa...@gmail.com>.
Where would I put that statement? In my action class I return
mapping.findForward("anything"); in all cases. In all my other classes
its just getters and setters.
- Paul
>
>
Shinobu Kawai wrote:
>Hi Paul,
>
>
>
>>I have written a few java files and rewrote a template to be more like a
>>template rather then standard html. When I tried to view the webpage I
>>found that I have a NullPointerException. Usually when there is a NPE
>>the compiler tells me where in my code the NPE is coming from. However
>>it just starts out with
>>"org.apache.velocity.tools.struts.StrutsUtils.getMessageResources(StrutsUtils.java:211)"
>>
>>
>
>Source says, you didn't give it a ServletContext, or a ModuleConfig
>could not be found.
> return (MessageResources)app.getAttribute(Globals.MESSAGES_KEY +
> moduleConfig.getPrefix());
>
>
>>I think the problem is that the properties file I defined is not moved
>>to the classes directory when the javacode is compiled. How do I do
>>that if I am using Ant to compiule my source code? However when I did
>>move the properties file into the right directory, I still get the same
>>error. Oh yeah this happens on all velocity pages that I created
>>before I changed the code.
>>
>>If you need to see the entire error please let me know and I will
>>provide it.
>>
>>
>
>I think it would. Better yet, you could show us some minimal code to
>reproduce your problem. ;)
>
>As for the Ant question, the Ant User List would be a better place to ask.
> http://ant.apache.org/mail.html
>
>Best regards,
>-- Shinobu
>
>--
>Shinobu Kawai <sh...@gmail.com>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: NullPointerException problem
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Paul,
> I have written a few java files and rewrote a template to be more like a
> template rather then standard html. When I tried to view the webpage I
> found that I have a NullPointerException. Usually when there is a NPE
> the compiler tells me where in my code the NPE is coming from. However
> it just starts out with
> "org.apache.velocity.tools.struts.StrutsUtils.getMessageResources(StrutsUtils.java:211)"
Source says, you didn't give it a ServletContext, or a ModuleConfig
could not be found.
return (MessageResources)app.getAttribute(Globals.MESSAGES_KEY +
moduleConfig.getPrefix());
> I think the problem is that the properties file I defined is not moved
> to the classes directory when the javacode is compiled. How do I do
> that if I am using Ant to compiule my source code? However when I did
> move the properties file into the right directory, I still get the same
> error. Oh yeah this happens on all velocity pages that I created
> before I changed the code.
>
> If you need to see the entire error please let me know and I will
> provide it.
I think it would. Better yet, you could show us some minimal code to
reproduce your problem. ;)
As for the Ant question, the Ant User List would be a better place to ask.
http://ant.apache.org/mail.html
Best regards,
-- Shinobu
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org