Okay, this is driving me crazy. I'm trying to write a servlet that serves up
WML to a wireless device and I keep getting a server 500 (NullPointerException)
error:
java.lang.NullPointerException
at java.io.File.(File.java:181)
at PageViewer.loadDataFile(PageViewer.java:16)
at PageViewer.init(PageViewer.java:13)
at org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
at org.apache.tomcat.core.Handler.init(Handler.java:215)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:296)
at org.apache.tomcat.core.Handler.service(Handler.java:254)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp
12ConnectionHandler.java:166)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
The relevant part of my web.xml (in the /webapps/wap/WEB-INF directory) is:
<servlet>
<servlet-name>
waptest
</servlet-name>
<servlet-class>
PageViewer
</servlet-class>
<init-param>
<param-name>dataFile</param-name>
<param-value>servlet.dat</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>
waptest
</servlet-name>
<url-pattern>
/wap/*
</url-pattern>
</servlet-mapping>
The runtime is choking at the instantiation of the File object:
public void init( ServletConfig config) throws ServletException {
super.init( config);
String dataFile = config.getInitParameter( "dataFile");
loadDataFile( dataFile);
}
void loadDataFile( String dataFile) {
File file = new File( dataFile);
String absolutePath = file.getAbsolutePath();
if( file.exists()) {
log( "Loading data file " + absolutePath);
loadDataFile( file);
} else {
log( "Can't find data file " + absolutePath);
}
}
This is right out of John Cook's "WAP Servlets" book, but of course he fails to
give any clue whatsoever about how ServletConfig is passing the required
parameter ("dataFile"). servlet.dat is in the /webapps/wap/WEB-INF/classes
directory because Cook's only hint is that it goes in the same package as the
servlet classes. I am using the default package. I am using Tomcat 3.2.1 as an
out-of-process servlet container to Win2kPro PWS 5.0. I am coding with Forte CE
2.0. I am compiling/distributing with Ant. And yes, I am restarting Tomcat
whenever I change anything.
Any clues, guys?
Thanks, and cheers!
Mark
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html