Steve R Burrus ha scritto:
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
line #19 is "while ((read = is.read(bytes)) != -1) {" ?
if so do you can check that "is" is not null?
Are you using some logging system? (log4j?)
Try to put "is.read(bytes)" before the loop and reload the page.
If the problem is on that line check the path of the file.
Edoardo
--
[EMAIL PROTECTED]
AIM: edoardopn
Jabber: [EMAIL PROTECTED]
tel:075 9142766
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]