[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tomcat-user
Subject:    Re: Need Help w. Null Pointer Exception.
From:       David Smith <dns4 () cornell ! edu>
Date:       2006-08-30 11:31:22
Message-ID: 44F5770A.5090801 () cornell ! edu
[Download RAW message or body]

getResourceAsStream() will return null if the requested resource is not 
available.  Keep in mind that getRequestAsStream() is rooted to your 
webapp, so the requested image needs to be found relative to the top 
level of your web application.

--David

Steve R Burrus wrote:

> I need some pretty immediate help/assistance with always getting a 
> NullPointerException Java exception when I try to view a particular 
> image in my favorite web browser!!! The line of text in my servlet 
> file which is, I think, problemmatic is a while loop. Well here is my 
> entire servlet file for someone to take a look at to hopefully help me 
> with this problem.
>
>                     package org.stephen.burris;
>
>                         import java.io.*;
>                         import javax.servlet.*;
>                         import javax.servlet.http.*;
>
>  public class One_More_Time extends HttpServlet {
>     public void doGet(HttpServletRequest rq, HttpServletResponse rp ) 
> throws
>                       ServletException, IOException {
>        rp.setContentType( "image/jpeg" );
>
>        ServletContext sc = getServletContext ();
>        InputStream is = sc.getResourceAsStream("/pamandersonnaked.jpeg");
>
>        int read = 0;
>        byte [] bytes = new byte[ 1024 ];
>
>        OutputStream os = rp.getOutputStream ();
>        while ((read = is.read(bytes)) != -1) {
>        os.write( bytes, 0, read);
>        }
>
>        os.flush();
>        os.close();
>   }
> }
>
> And the server error :
>
>  HTTP Status 500 -
>
> ------------------------------------------------------------------------
>
> type Exception report
>
> message
>
> description The server encountered an internal error () that prevented 
> it from fulfilling this request.
>
> exception
>
> java.lang.NullPointerException
>     org.stephen.burris.One_More_Time.doGet(One_More_Time.java:19)
>     javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>
> note The full stack trace of the root cause is available in the Apache 
> Tomcat/5.5.17 logs.
>
> ------------------------------------------------------------------------
>
>
>      Apache Tomcat/5.5.17
>
>
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic