title: Java: initialize an inner class to get the data of it at the right position
body: <p>I am parsing a message in the ShenzhenDecoder class - decode() method. After parsing it I am building the xml file in the ShenzhenRecoder class. But I am facing a problem to get the data out of the statusFlag class after setting the data in the ShenzhenDecoder class - assignStatusFlagMaptoRecorder(). Where and how have I to initialize the  inner StatusFlag class in the ShenzhenDecoder to get its data in side <code>createXMLFromRecord()</code>? since I am getting null for getStatusflag() and an exception for getStausFlag().getLowBattery() because getStatusflag() null is.</p>
  
  <p><strong>ShenzhenDecoder</strong></p>
  
  <p>public class ShenzhenDecoder {</p>
  
  <pre><code>ShenzhenRecord record = null;
  
  LinkedHashMap&lt;String, String&gt; statusFlagMap = new LinkedHashMap&lt;String, String&gt;();
  
  
  public ShenzhenRecord decode(final byte[] data) {
          this.record = new ShenzhenRecord();
          byte[] imeiArray = Arrays.copyOfRange(data, 1, 16);
          String imei = new String(imeiArray, "UTF-8");
          System.out.println("IMEI: " + imei);
          this.record.setImei(imei);
  
  }
  
  
  private void assignStatusFlagMaptoRecorder() {
      StatusFlag statusFlagRecord = this.record.new StatusFlag();
      for (Entry&lt;String, String&gt; entry : this.statusFlagMap.entrySet()) {
          String key = entry.getKey();
          switch (key) {
          case "lowBattery":
              statusFlagRecord.setLowBattery(entry.getValue());
              break;
          case "spare1BitFirstByte":
              statusFlagRecord.setSpare1BitFirstByte(entry.getValue());
              break;
  
          case "lbs":
              statusFlagRecord.setLbs(entry.getValue());
              break;
          case "gmsBlindArea":
              statusFlagRecord.setGmsBlindArea(entry.getValue());
              break;
          }
  
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Shenzhenrecord</strong></p>
  
  <pre><code>public class ShenzhenRecord {
  
      private String imei;
      private StatusFlag statusFlag;
  
  
      public String getImei() {
          return this.imei;
      }
  
  
      public void setImei(String imei) {
          this.imei = imei;
      }
  
      public class StatusFlag {
  
          private String lowBattery;
  
  
          public String getLowBattery() {
              return this.lowBattery;
          }
  
  
          public void setLowBattery(String lowBattery) {
              this.lowBattery = lowBattery;
          }
  
      }
  
  
      public Document createXMLFromRecord(String code) throws ApplicationException {
  
          Document document = DocumentHelper.createDocument();
  
          Element shenzhenElement = document.addElement("shenzhen");
  
          shenzhenElement.addAttribute("imei", getImei());
  
          Element statusFlagElement = shenzhenElement.addElement("statusFlag");
  
          StatusFlag statusFlagtest = this.getStatusFlag();
          //Here I am getting an error because getStatusFlag() has null.
          String lowBatteryTest = this.getStatusFlag().getLowBattery();
  
          statusFlagElement.addAttribute("lowBattery", this.getStatusFlag().getLowBattery());
  
          }
  
      return document;
  }
  
  }
  </code></pre>