aspose file tools*
The moose likes Servlets and the fly likes NullPointerError In Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "NullPointerError In Servlet" Watch "NullPointerError In Servlet" New topic
Author

NullPointerError In Servlet

Art Smith
Ranch Hand

Joined: Dec 12, 2000
Posts: 33
Hi,
I'm trying to get a small test servlet to work under Tomcat and I'm getting the following error:
Internal Servlet Error:
java.lang.NullPointerException
at java.lang.ClassLoader.resolveClass0(Native Method)
at java.lang.ClassLoader.resolveClass(ClassLoader.java:588)
at org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(AdaptiveClassLoader.java:430)
at org.apache.tomcat.loader.AdaptiveServletLoader.loadClass(AdaptiveServletLoader.java:174)
at org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:265)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:289)
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.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
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)

I'm running Tomcat 3.2.1 with Apache on Win98. The example servlets and JSP's work.
Any suggestions?
Art


Arthur Smith<br />SCJP2 - SCWCD
Software Engg
Greenhorn

Joined: Feb 19, 2001
Posts: 10
Art,
It will b helpful if u provide with the sample code

Praveen
Art Smith
Ranch Hand

Joined: Dec 12, 2000
Posts: 33
Here's the source code for the servlet. It's your basic "HelloWorld" type of app.
package servlets;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class TestServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
StringBuffer doc = new StringBuffer();
doc.append("<html>");
doc.append("<head><title>My Doc</title></head>");
doc.append("<body>");
doc.append("<H1> My Basic Test Servlet </h1>");
doc.append("</body></html>");
out.println(doc.toString());
out.close();
}
catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
Scott Stirling
Greenhorn

Joined: Mar 05, 2001
Posts: 24
The servlet looks fine. I'd guess that Tomcat can't load it for configuration reasons, such as that you misspelled the servlet-name in web.xml, or the servlet class is not in Tomcat's CLASSPATH.


Scott Stirling<BR>Author of <A HREF="http://www.amazon.com/exec/obidos/ASIN/067231939X/ref=ase_electricporkchop/107-2476442-4883722" TARGET=_blank rel="nofollow">Java Server Pages Application Development</A>
vikinsa
Ranch Hand

Joined: Apr 18, 2001
Posts: 46
The biggest problem like this I have ever faced in servlets or JSPs is due to request.getParamater(). If yuor program is expecting some inputs from the last event(like form submission) and it is not recieving it properly but tries to process it, NullPointerException may occur. But the piece of code will help me to answer your question more precisely.

Originally posted by Art Smith:
Hi,
I'm trying to get a small test servlet to work under Tomcat and I'm getting the following error:
Internal Servlet Error:
java.lang.NullPointerException
at java.lang.ClassLoader.resolveClass0(Native Method)
at java.lang.ClassLoader.resolveClass(ClassLoader.java:588)
at org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(AdaptiveClassLoader.java:430)
at org.apache.tomcat.loader.AdaptiveServletLoader.loadClass(AdaptiveServletLoader.java:174)
at org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:265)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:289)
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.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
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)

I'm running Tomcat 3.2.1 with Apache on Win98. The example servlets and JSP's work.
Any suggestions?
Art


------------------
Vikas Aggarwal
Technology Associate
http://www.vikinsa.com


Vikas Aggarwal<BR>Technology Associate<BR>http://www.vikinsa.com
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NullPointerError In Servlet