Re. Null Pointer Exception.

From: Steve R. Burrus (burrus1_at_swbell.net)
Date: 03/29/05


Date: Tue, 29 Mar 2005 20:39:02 GMT

I know that SOME of you think that I am being "crazy" and foolhardy by still
posting my problem about getting that "java.lang.NullPointerException"
almost every time that I try/attempt to view a servlet image in my browser,
but I swear, I have looked OVER AND OVER at the lines in the servlet file
which I suspect could be giving me this server error, but I honestly could
not find the problem! Truth In Representation : I HAVE been able to view
just a few of the images successfully, but I really don't know why. Well,
with my apologies to those of you who don't feel like I need again the
servlet code, I humbly re-submit it to you :

                      package com.laundry.gal;

                        import java.io.*;
                        import javax.servlet.*;
                        import javax.servlet.http.*;

 public class LuvThisGal extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse
response) throws
                  IOException,ServletException {
     response.setContentType("image/jpg");

  ServletContext ctx = getServletContext();
  InputStream is = ctx.getResourceAsStream("/GirlAtSink.jpeg");

  int read = 0;
  byte[] bytes = new byte[1024];

  OutputStream os = response.getOutputStream();

  while((read = is.read(bytes)) != -1) {
   os.write(bytes, 0, read);
        response.sendError(500,"Hey! Your Servlet Developed A" +
                    "NullPointerException.");

     }
     os.flush();
     os.close();

    }
}



Relevant Pages

  • Re: Re. Null Pointer Exception.
    ... > I try/attempt to view a servlet image in my browser, ... > servlet file which I suspect could be giving me this ... If there is more than one dereferenced pointer on ... Once you have identified the null pointer, ...
    (comp.lang.java.programmer)
  • Re: can i include query in URL?
    ... i lost my original posting... ... > resultsPg is a servlet. ... > from the list (rownumber). ...
    (comp.lang.java.programmer)
  • Re: can i include query in URL?
    ... i lost my original posting... ... > resultsPg is a servlet. ... > from the list (rownumber). ...
    (comp.lang.java)