Null  pointer on no name value pair

Posted on 2004-11-24
Last Modified: 2011-09-20
If I pass in a name value pair for "platform" my code worksbut if I don't I get a null pointer exception. Why am I getting that?I  (works)  (does NOT work)
    HttpSession sess = request.getSession(true);
    String nfsu2SelectedPlatform = (String)sess.getValue("nfsu2SelectedPlatform");
    String platform = request.getParameter("platform");
     if (nfsu2SelectedPlatform.equals("null")) {
        sess.setAttribute("nfsu2SelectedPlatform", "ps2");
          platform ="ps2";
       } else {
              if ((!(nfsu2SelectedPlatform.equals(platform)))&&(!(platform.equals("null")))){
         sess.setAttribute("nfsu2SelectedPlatform", platform);
Question by:894359
    LVL 92

    Accepted Solution

    >           if ((!(nfsu2SelectedPlatform.equals(platform)))&&(!(platform.equals("null")))){

    should be:

              if (platform!=null && !nfsu2SelectedPlatform.equals(platform)){
    LVL 92

    Expert Comment

    >     if (nfsu2SelectedPlatform.equals("null")) {

    similiarly for this:

        if (nfsu2SelectedPlatform!=null) {

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now