Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Help--Null Pointer Exception

Reply
Thread Tools

Help--Null Pointer Exception

 
 
Steve R. Burrus
Guest
Posts: n/a
 
      02-28-2005
Yes, I need some help/assistance with always getting this particular
servlet error exception when I try to execute an image servlet! Can
someone help me? (And look below the error msg. for the file itself)

>>"SEVERE: Servlet.service() for servlet MyLuciousGirl threw exception

java.lang.NullPointerException
at com.steven.burris.LaundryGirl.doGet(LaundryGirl.ja va:24)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
at
org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(Appl
icationFilterChain.java:252)
at
org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationF
ilterChain.java:173)
at
org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperV
alve.java:214)
at
org.apache.catalina.core.StandardContextValve.invo ke(StandardContextV
alve.java:17
at
org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.j
ava:126)
at
org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.j

..........."<<

>>"package com.steven.burris;


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

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

ServletContext sc = getServletContext ();
InputStream is = sc.getResourceAsStream("/MyBeautifulGirl.jpg");

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

OutputStream os = resp.getOutputStream();
while( ( read = is.read(bytes)) != -1){
os.write(bytes, 0, read);
}
os.flush();
os.close();
}"<<
 
Reply With Quote
 
 
 
 
Rhino
Guest
Posts: n/a
 
      02-28-2005

"Steve R. Burrus" <(E-Mail Removed)> wrote in message
news:VfwUd.19985$(E-Mail Removed). com...
> Yes, I need some help/assistance with always getting this particular
> servlet error exception when I try to execute an image servlet! Can
> someone help me? (And look below the error msg. for the file itself)
>
> >>"SEVERE: Servlet.service() for servlet MyLuciousGirl threw exception

> java.lang.NullPointerException
> at com.steven.burris.LaundryGirl.doGet(LaundryGirl.ja va:24)
> at javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
> at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
> at
> org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(Appl
> icationFilterChain.java:252)
> at
> org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationF
> ilterChain.java:173)
> at
> org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperV
> alve.java:214)
> at
> org.apache.catalina.core.StandardContextValve.invo ke(StandardContextV
> alve.java:17
> at
> org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.j
> ava:126)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.j
>
> .........."<<
>
> >>"package com.steven.burris;

>
> import java.io.*;
> import java.awt.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class LaundryGirl extends HttpServlet {
> public void doGet(HttpServletRequest req, HttpServletResponse resp) throws
> ServletException, IOException {
> resp.setContentType("image/jpeg");
>
> ServletContext sc = getServletContext ();
> InputStream is = sc.getResourceAsStream("/MyBeautifulGirl.jpg");
>
> int read = 0;
> byte[] bytes = new byte[1024];
>
> OutputStream os = resp.getOutputStream();
> while( ( read = is.read(bytes)) != -1){
> os.write(bytes, 0, read);
> }
> os.flush();
> os.close();
> }"<<


Uhh, which line in 'LaundryGirl' is line 24? I tried counting down 24 lines
from the top of the listing but that is the 'os.close();' line and it seems
unlikely you'd get a NullPointerException there when the os.flush() just
before it apparently worked. Something tells me that there are some extra
blank lines or some wrapping throwing off the count....

By the way, I don't know if this is significant but I noticed that in your
package name, your last name is spelled 'Burris' but in your email ID, it is
'Burrus'. I'm not sure which of those is incorrect but if you've made a
similar typo in your code, perhaps something isn't getting found because
you've specified the wrong directory for it or something like that....

Rhino





 
Reply With Quote
 
 
 
 
Dotty
Guest
Posts: n/a
 
      02-28-2005

"Rhino" <(E-Mail Removed)> wrote in message
news:1lxUd.4828$(E-Mail Removed).. .
>
> "Steve R. Burrus" <(E-Mail Removed)> wrote in message
> news:VfwUd.19985$(E-Mail Removed). com...
> > Yes, I need some help/assistance with always getting this particular
> > servlet error exception when I try to execute an image servlet! Can
> > someone help me? (And look below the error msg. for the file itself)
> >
> > >>"SEVERE: Servlet.service() for servlet MyLuciousGirl threw exception

> > java.lang.NullPointerException
> > at com.steven.burris.LaundryGirl.doGet(LaundryGirl.ja va:24)
> > at javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
> > at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
> > at
> > org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(Appl
> > icationFilterChain.java:252)
> > at
> > org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationF
> > ilterChain.java:173)
> > at
> > org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperV
> > alve.java:214)
> > at
> > org.apache.catalina.core.StandardContextValve.invo ke(StandardContextV
> > alve.java:17
> > at
> > org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.j
> > ava:126)
> > at
> > org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.j
> >
> > .........."<<
> >
> > >>"package com.steven.burris;

> >
> > import java.io.*;
> > import java.awt.*;
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> >
> > public class LaundryGirl extends HttpServlet {
> > public void doGet(HttpServletRequest req, HttpServletResponse resp)

throws
> > ServletException, IOException {
> > resp.setContentType("image/jpeg");
> >
> > ServletContext sc = getServletContext ();
> > InputStream is = sc.getResourceAsStream("/MyBeautifulGirl.jpg");
> >
> > int read = 0;
> > byte[] bytes = new byte[1024];
> >
> > OutputStream os = resp.getOutputStream();
> > while( ( read = is.read(bytes)) != -1){
> > os.write(bytes, 0, read);
> > }
> > os.flush();
> > os.close();
> > }"<<

>
> Uhh, which line in 'LaundryGirl' is line 24? I tried counting down 24

lines
> from the top of the listing but that is the 'os.close();' line and it

seems
> unlikely you'd get a NullPointerException there when the os.flush() just
> before it apparently worked. Something tells me that there are some extra
> blank lines or some wrapping throwing off the count....


If 'os' is null then 'os.close()' will give the NullPointerException
message.


 
Reply With Quote
 
Tony Morris
Guest
Posts: n/a
 
      02-28-2005


"Steve R. Burrus" <(E-Mail Removed)> wrote in message
news:VfwUd.19985$(E-Mail Removed). com...
> Yes, I need some help/assistance with always getting this particular
> servlet error exception when I try to execute an image servlet! Can
> someone help me? (And look below the error msg. for the file itself)
>
> >>"SEVERE: Servlet.service() for servlet MyLuciousGirl threw exception

> java.lang.NullPointerException
> at com.steven.burris.LaundryGirl.doGet(LaundryGirl.ja va:24)
> at javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
> at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
> at
> org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(Appl
> icationFilterChain.java:252)
> at
> org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationF
> ilterChain.java:173)
> at
> org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperV
> alve.java:214)
> at
> org.apache.catalina.core.StandardContextValve.invo ke(StandardContextV
> alve.java:17
> at
> org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.j
> ava:126)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.j
>
> .........."<<
>
> >>"package com.steven.burris;

>
> import java.io.*;
> import java.awt.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class LaundryGirl extends HttpServlet {
> public void doGet(HttpServletRequest req, HttpServletResponse resp) throws
> ServletException, IOException {
> resp.setContentType("image/jpeg");
>
> ServletContext sc = getServletContext ();
> InputStream is = sc.getResourceAsStream("/MyBeautifulGirl.jpg");
>
> int read = 0;
> byte[] bytes = new byte[1024];
>
> OutputStream os = resp.getOutputStream();
> while( ( read = is.read(bytes)) != -1){
> os.write(bytes, 0, read);
> }
> os.flush();
> os.close();
> }"<<


http://www.xdweb.net/~dibblego/java/NPE

--
Tony Morris
http://xdweb.net/~dibblego/


 
Reply With Quote
 
Tilman Bohn
Guest
Posts: n/a
 
      02-28-2005
In message <(E-Mail Removed)>,
Dotty wrote on Sun, 27 Feb 2005 23:03:46 -0600:

[...]
>> > OutputStream os = resp.getOutputStream();
>> > while( ( read = is.read(bytes)) != -1){
>> > os.write(bytes, 0, read);
>> > }
>> > os.flush();
>> > os.close();
>> > }"<<

>>
>> Uhh, which line in 'LaundryGirl' is line 24? I tried counting down 24

> lines
>> from the top of the listing but that is the 'os.close();' line and it

> seems
>> unlikely you'd get a NullPointerException there when the os.flush() just
>> before it apparently worked. Something tells me that there are some extra
>> blank lines or some wrapping throwing off the count....

>
> If 'os' is null then 'os.close()' will give the NullPointerException
> message.


No. Because the os.flush() right before it would have thrown that
same exception already, os.close() would never execute.

--
Cheers, Tilman

`Boy, life takes a long time to live...' -- Steven Wright
 
Reply With Quote
 
Tilman Bohn
Guest
Posts: n/a
 
      02-28-2005
In message <VfwUd.19985$(E-Mail Removed)> ,
Steve R. Burrus wrote on Mon, 28 Feb 2005 03:31:01 GMT:

> >>"SEVERE: Servlet.service() for servlet MyLuciousGirl threw exception

> java.lang.NullPointerException
> at com.steven.burris.LaundryGirl.doGet(LaundryGirl.ja va:24)

[...]

> ServletContext sc = getServletContext ();
> InputStream is = sc.getResourceAsStream("/MyBeautifulGirl.jpg");


You should check if you really got an InputStream...

> int read = 0;
> byte[] bytes = new byte[1024];
>
> OutputStream os = resp.getOutputStream();
> while( ( read = is.read(bytes)) != -1){


I suspect this is line 24. Is it?

--
Cheers, Tilman

`Boy, life takes a long time to live...' -- Steven Wright
 
Reply With Quote
 
Dotty
Guest
Posts: n/a
 
      02-28-2005

"Tilman Bohn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). com...
> In message <(E-Mail Removed)>,
> Dotty wrote on Sun, 27 Feb 2005 23:03:46 -0600:
>
> [...]
> >> > OutputStream os = resp.getOutputStream();
> >> > while( ( read = is.read(bytes)) != -1){
> >> > os.write(bytes, 0, read);
> >> > }
> >> > os.flush();
> >> > os.close();
> >> > }"<<
> >>
> >> Uhh, which line in 'LaundryGirl' is line 24? I tried counting down 24

> > lines
> >> from the top of the listing but that is the 'os.close();' line and it

> > seems
> >> unlikely you'd get a NullPointerException there when the os.flush()

just
> >> before it apparently worked. Something tells me that there are some

extra
> >> blank lines or some wrapping throwing off the count....

> >
> > If 'os' is null then 'os.close()' will give the NullPointerException
> > message.

>
> No. Because the os.flush() right before it would have thrown that
> same exception already, os.close() would never execute.


Ok Mr. picky, if 'os' is null then 'os.write()' would fail before the
'os.flush()'


 
Reply With Quote
 
Tilman Bohn
Guest
Posts: n/a
 
      02-28-2005
In message <(E-Mail Removed)>,
Dotty wrote on Mon, 28 Feb 2005 14:33:31 -0600:

[...]
>> >> > OutputStream os = resp.getOutputStream();
>> >> > while( ( read = is.read(bytes)) != -1){
>> >> > os.write(bytes, 0, read);
>> >> > }
>> >> > os.flush();
>> >> > os.close();
>> >> > }"<<

[...]
>> > If 'os' is null then 'os.close()' will give the NullPointerException
>> > message.

>>
>> No. Because the os.flush() right before it would have thrown that
>> same exception already, os.close() would never execute.

>
> Ok Mr. picky, if 'os' is null then 'os.write()' would fail before the
> 'os.flush()'


Yeah, but only if it even gets there, which is not the case if the
InputStream didn't have any data.

--
Cheers, Tilman

`Boy, life takes a long time to live...' -- Steven Wright
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Exception safe & Exception Neutral deep_copy smart pointer Nindi73@yahoo.co.uk C++ 3 11-10-2006 10:55 AM
C++ Exception: Why does this program behave differently for pointer and array of pointer Divick C++ 7 09-12-2005 05:49 AM
Pointer-to-pointer-to-pointer question masood.iqbal@lycos.com C Programming 10 02-04-2005 02:57 AM



Advertisments