title: Android Dialog showing null pointer when trying to post a Dialog form to a http URL
body: <p>I am new to android and this is my question, I have a dialog form that pops up which is suppose to submit a form to a URL using android Http post, when I click the submit button of the form it force closes the app and I get an error message from the logcat saying its a null pointer.</p>
  
  <pre><code>protected Dialog onCreateDialog(int id) {
      switch (id) {
          case DIALOG_TEXT_ENTRY:
              //This shows how to add a custom layout to an AlertDialog 
              LayoutInflater factory = LayoutInflater.from(this);
              final View textEntryView = factory.inflate(R.layout.commentlayout, null);
              return new AlertDialog.Builder(HomeActivity.this)
                  .setIcon(R.drawable.ic_launcher)
                  .setTitle(R.string.app_name)
                  .setView(textEntryView)
                  .setPositiveButton(R.string.Submit, new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
  
                      postComment();
  
                  }
              })
                  .setNegativeButton(R.string.cancal, new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                      /* User clicked cancel so do some stuff */
                  }
              }).create();
      }
      return null;
  }
  
  //this comes after the setContentView(R.Layout.view)
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.view);
  
      public void postComment() {
  
          nameField = (EditText) findViewById(R.id.editText1);
          countryField = (EditText) findViewById(R.id.editText2);
          commentField = (EditText) findViewById(R.id.commentField);
  
          //get message from message fields
          String name = nameField.getText().toString();
          String count = countryField.getText().toString();
          String comm = commentField.getText().toString();
  
          //check whether the name field is empty or not
          if (name.length() &gt; 0) {
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost("http://_______");
  
              try {
                  List &lt; NameValuePair &gt; nameValuePairs = new ArrayList &lt; NameValuePair &gt; (3);
  
                  nameValuePairs.add(new BasicNameValuePair("namet", name));
                  nameValuePairs.add(new BasicNameValuePair("countryt", count));
                  nameValuePairs.add(new BasicNameValuePair("commentt", comm));
                  httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                  httpclient.execute(httppost);
  
                  nameField.setText(""); //reset the message text field
                  countryField.setText("");
                  commentField.setText("");
  
                  Toast.makeText(getBaseContext(), "Sent", Toast.LENGTH_SHORT).show();
              } catch (ClientProtocolException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          } else {
              //display message if text field is empty
              Toast.makeText(getBaseContext(), "All fields are required", Toast.LENGTH_SHORT).show();
          }
  </code></pre>