title: NullPointerException in liferay portlet
body: <p>this is in my portlet class : </p>
  
  <pre><code>import java.io.IOException;
  
  import javax.portlet.ActionRequest;
  import javax.portlet.ActionResponse;
  import javax.portlet.GenericPortlet;
  import javax.portlet.PortletException;
  import javax.portlet.PortletMode;
  import javax.portlet.PortletPreferences;
  import javax.portlet.PortletRequestDispatcher;
  import javax.portlet.PortletURL;
  import javax.portlet.RenderRequest;
  import javax.portlet.RenderResponse;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  public class HelloYouPortlet extends GenericPortlet {
      public void init() throws PortletException {
          editJSP = getInitParameter("edit-jsp");
          viewJSP = getInitParameter("view-jsp");
      }
  
      public void doEdit(RenderRequest renderRequest,
              RenderResponse renderResponse) throws IOException, PortletException {
          renderResponse.setContentType("text/html");
          PortletURL addNameURL = renderResponse.createActionURL();
          addNameURL.setParameter("addName", "addName");
          renderRequest.setAttribute("addNameURL", addNameURL.toString());
          include(editJSP, renderRequest, renderResponse);
      }
  
      public void doView(RenderRequest renderRequest,
              RenderResponse renderResponse) throws IOException, PortletException {
          PortletPreferences prefs = renderRequest.getPreferences();
          String username = (String) prefs.getValue("name", "no");
          if (username.equalsIgnoreCase("no")) {
              username = "";
          }
          renderRequest.setAttribute("userName", username);
          include(viewJSP, renderRequest, renderResponse);
      }
  
      public void processAction(ActionRequest actionRequest,
              ActionResponse actionResponse) throws IOException, PortletException {
          String addName = actionRequest.getParameter("addName");
          if (addName != null) {
              PortletPreferences prefs = actionRequest.getPreferences();
              prefs.setValue("name", actionRequest.getParameter("username"));
              prefs.store();
              actionResponse.setPortletMode(PortletMode.VIEW);
          }
      }
  
      protected void include(String path, RenderRequest renderRequest,
              RenderResponse renderResponse) throws IOException, PortletException {
          PortletRequestDispatcher portletRequestDispatcher = getPortletContext()
                  .getRequestDispatcher(path);
          if (portletRequestDispatcher == null) {
              _log.error(path + " is not a valid include");
          } else {
              portletRequestDispatcher.include(renderRequest, renderResponse);
          }
      }
  
      protected String editJSP;
      protected String viewJSP;
      private static Log _log = LogFactory.getLog(HelloYouPortlet.class);
  
  }
  </code></pre>
  
  <p>and this is on my view.jsp : </p>
  
  <pre><code>&lt;%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %&gt;
  &lt;jsp:useBean id="userName" class="java.lang.String" scope="request" /&gt;
  &lt;portlet:defineObjects /&gt;
  &lt;p&gt;This is the Hello You portlet.&lt;/p&gt;
  &lt;p&gt;Hello &lt;%= userName %&gt;!&lt;/p&gt;
  </code></pre>
  
  <p>and my edit.jsp : </p>
  
  <pre><code>&lt;%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%&gt;
  &lt;jsp:useBean class="java.lang.String" id="addNameURL" scope="request" /&gt;
  &lt;portlet:defineObjects /&gt;
  &lt;form id="&lt;portlet:namespace /&gt;helloForm" action="&lt;%=addNameURL%&gt;"
      method="post"&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;Name:&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="username"&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;input type="submit" id="nameButton" title="Add Name" value="Add Name"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>when I deploy it in command prompt, I got "build successful" but when I install it on liferay portal and I got java.lang.NullPointerException at line 3 in doView method (if statament), please tell me why my local variable username got null.
  By the way, this portlet example is on liferay in action book.
  thanks for reading my question.</p>