title: Getting null pointer exception when I run the following code
body: <p>I have servlet in which it passes the map object from servlet to jsp and in jsp I will iterate over the map and display the values. But I getting null pointer exception when I pass the map object in setattribute method</p>
  
  <pre><code>try
      {
  
              Map&lt;String,String&gt; A=new HashMap&lt;String,String&gt;();
      Class.forName("com.mysql.jdbc.Driver");
      connect=(Connection) DriverManager.getConnection("Connection");
      statement =(Statement)connect.createStatement();
      result=(ResultSet)statement.executeQuery("query");
      while(result.next())
      {
          A.put(result.getString("Hi"),result.getString("Hello"));
      }
  
      ServletContext context=getServletContext();
  
      request.setAttribute("A",A); // when I run i getting nullpointer exception here
      RequestDispatcher rd=context.getRequestDispatcher("/next.jsp");
      rd.forward(request, response);
  </code></pre>
  
  <p>stacktrace: </p>
  
  <blockquote>
  <pre><code>  java.lang.NullPointerException
  at search.classy.ClassDB.dbConnect(ClassDB.java:61)
  </code></pre>
  </blockquote>