Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerError In Servlet

 
Art Smith
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Software Engg
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Art,
It will b helpful if u provide with the sample code

Praveen
 
Art Smith
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vikinsa
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic