title: How to troubleshoot a NullPointerException on Android?
body: <p>My program is immediately crashing on my Android Emulator and I receive this in the Eclipse Console:</p>
  
  <pre><code>java.lang.NullPointerException
      at com.android.ddmlib.Client.sendAndConsume(Client.java:572)
      at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
      at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
      at com.android.ddmlib.Client.getJdwpPacket(Client.java:671)
      at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
      at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
  </code></pre>
  
  <p><strong>How can I troubleshoot what is throwing this message?</strong>  I'm new to Eclipse and Android.</p>
  
  <p>The program completely crashes when I try to launch a dialog with a button, and refers back here:</p>
  
  <pre><code>    @Override
      protected Dialog onCreateDialog(int id) {
          Dialog dialog;
          switch (id) {
          case TIME_DIALOG_ID:
              return new TimePickerDialog(this,
                      mTimeSetListener, mHour24, mMinute, false);
  
  
          case POWER_OFF_OPTIONS:
              AlertDialog.Builder builder;
              AlertDialog alertDialog;
  
              Context mContext = getApplicationContext();
              LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
              View layout = inflater.inflate(R.layout.options,
                      (ViewGroup)findViewById(R.id.relativeLayout1));
              //Capture view elements
              mChkAudio = (CheckBox) findViewById(R.id.chkAudio);
              mChkBluetooth = (CheckBox) findViewById(R.id.chkBlueTooth);
              mChkNetwork = (CheckBox) findViewById(R.id.chkNetwork);
              mChkWifi = (CheckBox) findViewById(R.id.chkWifi);
              mBtnOK = (Button) findViewById(R.id.btnOK);
              mBtnOK.setOnClickListener(new View.OnClickListener() {
                  public void onClick(View v) {
                    DismissPowerOptions();
                      }
              }); 
              builder = new AlertDialog.Builder(mContext);
              builder.setView(layout);
              alertDialog = builder.create();
              //return alertDialog;
          default:
              dialog = null;
          }
          return dialog;
      }
  </code></pre>