Hello i have the above code
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class CarSessionServlet2 extends HttpServlet {
    private String Brands[] = {
        "Audi", "Ford", "Toyota"
    };
    private String Cars[] = {
        "A3", "Fiesta", "Yaris"
    };
    private String screen = "name";
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // reaction
        if (screen.equals("name")) { //elegxos apo poia selida kalw tin doPost. Edw apo tin BrandsSelection.html
            String cookieName = request.getParameter("name"); // choice made
            // will be sent
            // back to
            // client
            String cookieBrand = request.getParameter("brands");
            PrintWriter output;
            HttpSession session = request.getSession(true);
            session.setAttribute("name", cookieName);
            session.setAttribute(cookieBrand, getCars(cookieBrand));
            response.setContentType("text/html");
            output = response.getWriter();
            // send HTML page to client
            output.println("<HTML><HEAD><meta charset='utf-8'><TITLE>");
            output.println("Cookies");
            output.println("</TITLE></HEAD><BODY>");
            output.println("<P>Welcome Ms./Mr.: ");
            // output.println( "<P>" );
            output.println(cookieName);
            output.println(" <BR> you have chosen ");
            output.println(cookieBrand);
            output.println("<BR><a href='SecondPage.html'>" + "Click here to continue..." + "</a>");
            output.println("</BODY></HTML>");
            output.close(); // close stream
            screen = "color";
        }
        if (screen.equals("color")) { //elegxos apo poia selida kalw tin doPost. Edw apo tin SecondPage.html
            PrintWriter output;
            String color = request.getParameter("color");
            HttpSession session = request.getSession(true);
            session.setAttribute("color", color);
            response.setContentType("text/html");
            output = response.getWriter();
            // send HTML page to client
            output.println("<HTML><HEAD><meta charset='utf-8'><TITLE>");
            output.println("Cookies");
            output.println("</TITLE></HEAD><BODY>");
            output.println("<FORM ACTION=\"http://localhost:8080/Askisi2Session/CarSessionServlet2\" METHOD=\"GET\">");
            output.println("<STRONG>To see your selections press the button:<br> </STRONG>");
            output.println("<INPUT TYPE=\"submit\" VALUE=\"Selections\">");
            output.println("</FORM>");
            output.println("</BODY></HTML>");
            output.close(); // close stream
            screen = "name";
        }
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // reaction
        // to
        // the
        // reception
        PrintWriter output; // of
        // GET
        response.setContentType("text/html");
        output = response.getWriter();
        output.println("<HTML><HEAD><meta charset='utf-8'><TITLE>");
        output.println("Cookie with your selections has been read !");
        output.println("</TITLE></HEAD><BODY>");
        HttpSession session = request.getSession(false); // get client's session;
        output.println("<H3>Here is your saved session data:</H3>");
        Enumeration e;
        if (session != null) {
            e = session.getAttributeNames();
        } else {
            e = null;
        }
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            output.println(name + ": " + session.getAttribute(name) + "<BR>");
        }
        output.println("<a href='BrandsSelection.html'>Click here to Restart...</a>");
        output.println("</BODY></HTML>");
        output.close(); // close stream
    }
    private String getCars(String conString) {
        for (int i = 0; i < Brands.length; ++i)
        if (conString.equals(Brands[i])) {
            return Cars[i];
        }
        return ""; // no matching string found
    }
} // END OF CLASS CookieServlet
when i run it with tomcat 8.0.28 i get a java.lang.NullPointerException mentioning 
java.lang.NullPointerException
CarSessionServlet2.getCars(CarSessionServlet2.java:155)
CarSessionServlet2.doPost(CarSessionServlet2.java:43)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Line 43 is that
session.setAttribute(cookieBrand,getCars(cookieBrand));
and line 155 is that
if (conString.equals(Brands[i])) {
First i open an html page, i fill up a textbox, make a choice on a radiobutton and then i press a submit button which calls the doPost method. Then A second html page appears. I fill up another text box and by pressing another submit button i call the doPost method again (2nd if statement, screen=color). And then..... NullPointerException. It was supposed to appear another html page with a button that calls the doGet method. I do not know why i take that exception
Html Page 1(BrandsSelection)
<HTML>
<HEAD>
   <TITLE>Cookie will be written in our disc</TITLE> 
</HEAD>
<BODY>
   <FORM ACTION="http://localhost:8080/Askisi2Session/CarSessionServlet2" METHOD="POST">      
      <STRONG>Enter Your Name:<br> </STRONG>
      <PRE>
      <INPUT TYPE="text" NAME="name"><br><br>
      <STRONG>Select the Brand of your Desire:<br> </STRONG>
      <PRE>
      <INPUT TYPE="radio" NAME="brands" VALUE="Audi">check here for Audi<BR>
      <INPUT TYPE="radio" NAME="brands" VALUE="Ford">check here for Ford<BR>
      <INPUT TYPE="radio" NAME="brands" VALUE="Toyota" CHECKED>check here for Toyota<BR>
      </PRE>
      <INPUT TYPE="submit" VALUE="Submit">
      <INPUT TYPE="reset"> </P>
   </FORM>
</BODY>
</HTML>
HTML PAGE 2(SeondPage)
<HTML>
<HEAD> 
   <TITLE>Cookie taken into Account</TITLE> 
</HEAD>
<BODY>
   <FORM ACTION="http://localhost:8080/Askisi2Session/CarSessionServlet2" METHOD="POST">
      <STRONG>What is your favorite color?<br> </STRONG>
      <PRE>
      <INPUT TYPE="text" NAME="color"><br>
      </PRE>
      <INPUT TYPE="submit" VALUE="Submit">
   </FORM>
</BODY>
</HTML>
 
    