STILL Need Help w. NullPointerException.

S

Steve R. Burrus

I posted this problem to the group the other nite, but alas, since it still
persists as a problem for me, I thought that i would re-submit it for anyone
to try to help me with it. The problem is still getting a server error
pointing to a "NullPointerException"!!! I really don't see at all any kind
of a null object reference or any problem like that could lead to such an
exception in this file :

package org.my.servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class My_Image extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("image/jpeg");

ServletContext con = getServletContext();
InputStream in = con.getResourceAsStream("/MyBeautifulGirl1.jpeg");

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

OutputStream os = resp.getOutputStream() ;
while(( read = in.read(bytes)) != -1){
os.write(bytes, 0, read);
}
os.flush();
os.close();
}
}
 
W

Wendy S

Steve R. Burrus said:
I posted this problem to the group the other nite, but alas, since it still
persists as a problem for me, I thought that i would re-submit it for
anyone to try to help me with it. The problem is still getting a server
error pointing to a "NullPointerException"!!! I really don't see at all any
kind of a null object reference or any problem like that could lead to such
an exception in this file :

Neither do we, since you STILL didn't identify the line on which the NPE is
occurring.
 
H

Hikikomori

My magic 8 ball says that the getResourceAsStream method returned a
null because the resource could not be found. So your InputStream
object was null and you tried to use it and a npe was thrown. Tada!

Of course, that's just what my magic 8 ball says.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top