If there are no cookies, it might throw a NullPointerException because u are
trying to access the variable (cookies.length) of an object which does not
exist. modify ur if statement to
if (cookies!=null && cookies.length)
I encountered the same problem for strings but never for cookies. This might
just solve the problem.

Yogeeta

> ----------
> From:         matt[SMTP:[EMAIL PROTECTED]]
> Reply To:     A mailing list about Java Server Pages specification and
> reference
> Sent:         Thursday, December 28, 2000 6:27 PM
> To:   [EMAIL PROTECTED]
> Subject:      help with a bean please
>
> can anyone tell me why this throws a java.lang.NullPointerException ?
>
> public String getCookieExists(){
>   String strStatus = "no errors";
>   Cookie info;
>   try{
>    if (request.getCookies() != null){
>     Cookie[] cookies = request.getCookies(); //null exception from here
>     if (cookies.length !=0 && cookies != null){
>      for (int i = 0; i < cookies.length ; i++){
>       info = cookies[i];
>       if (info != null){
>        strStatus = info.getName().equals(strCookieLookingFor) &&
> strCookieLookingFor != null ? "exists" : "doesnt exist";
>       }
>      }
>     }
>    }
>   }
>   catch(Exception e){
>    strStatus = (e.toString() + " <b>(from bean)</b>");
>   }
>
>   return strStatus;
>  }
>
> ==========================================================================
> =
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to