It's still about the NPE.

S

Steve R. Burrus

CAN someone help me with this problem of always getting the NPE whenever I
try to view only this particular servlet image in my browser. Here [AGAIN] I
submit the code for this servlet, if someone didn't see it the other day
when I initially posted this :

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
ServletException, IOException {
response.setContentType("image/jpeg");

ServletContext cnt = getServletContext() ;
InputStream is = cnt.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);
}

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

****************************************************************************************************************************************************
java.lang.NullPointerException
at com.laundry.gal.LuvThisGal.doGet(LuvThisGal.java:22)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
icationFilterChain.java:252)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
ilterChain.java:173)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapper
alve.java:214)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContext
alve.java:178)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.
ava:126)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.
ava:105)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVa
ve.java:107)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.ja
a:148)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.jav
:825)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proc
ssConnection(Http11Protocol.java:738)
at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndp
int.java:526)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFo
lowerWorkerThread.java:80)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Thread
ool.java:684)
at java.lang.Thread.run(Thread.java:595)"<<
 
M

Mike Schilling

Steve R. Burrus said:
CAN someone help me with this problem of always getting the NPE whenever I
try to view only this particular servlet image in my browser. Here [AGAIN]
I submit the code for this servlet, if someone didn't see it the other day
when I initially posted this :

[Code and stack trace snipped]

Almost there. Now you just need to tell us which line is 22. (If the
package statement were the first line, 22 would consist of just a closing
brace, which seems unlikely.)
 
W

Wendy S

Steve R. Burrus said:
CAN someone help me with this problem of always getting the NPE whenever I
try to view only this particular servlet image in my browser. Here [AGAIN]
I submit the code for this servlet, if someone didn't see it the other day
when I initially posted this :

We've seen it, three times now. Have you read any of the responses you've
already received? All you have to do is identify the line on which the NPE
is occurring. Your stack trace says it's line 22.
at com.laundry.gal.LuvThisGal.doGet(LuvThisGal.java:22)

^^
Which line is that? My guess is that there are two blank lines a the top of
the .java file, putting this line at 22:
while(( read = is.read(bytes)) != -1) {

And so all the people who answered you last time are probably right: your
input stream is null, and calling its read method is throwing the NPE. Go
back to this line:
InputStream is = cnt.getResourceAsStream("/GirlAtSink.jpeg");

And figure out what's not working. Are your files really named ".jpeg" and
not ".jpg"? Where, exactly, in the webapp file structure is this file
located?

If that's not really line 22, let us know...
 
K

Kevin McMurtrie

It's all about you not bothering to learn how to use a debugger.
Download Eclipse, point Eclipse to your source code, add the debug mode
arguments to JVM launch command, run it, then attach Eclipse's debugger.
 
R

Ryan Stewart

Steve R. Burrus said:
CAN someone help me with this problem of always getting the NPE whenever I try
to view only this particular servlet image in my browser. Here [AGAIN] I
submit the code for this servlet, if someone didn't see it the other day when
I initially posted this :
[...]

And just in case one more post will make a difference... This is the third time
that I and others have responded to this exact question, and the answer is
*still* the same.
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top