title: Android and JSP Communication Error
body: <p>I Have this JSP which just check the <code>username</code> and <code>password</code> and <code>"out.write"</code> <code>1</code> or <code>0</code> based on <code>true</code> or <code>false.</code></p>
  
  <pre><code>    &lt;%@ page import="java.io.*" %&gt;    
      &lt;%
          if(request.getParameter("username").equals("anas") &amp;&amp; request.getParameter("password").equals("azeem"))
          {
              out.write("1");
  
          }
          else
              out.write("0");
      %&gt; &lt;/br&gt;
  </code></pre>
  
  <p>Now my android code is somerhing like this</p>
  
  <pre><code>   @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_agent_login);
  
          edit_username = (EditText) findViewById(R.id.edit_username);
          edit_password = (EditText) findViewById(R.id.edit_password);
          btn_login = (Button) findViewById(R.id.btnLogin);
  
          if (android.os.Build.VERSION.SDK_INT &gt; 9) { // must add this code in
                              // order not to get the
                              // Exception while executing
                              // program
              StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                      .permitAll().build();
              StrictMode.setThreadPolicy(policy);
          }
  
          btn_login.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  username = edit_username.getText().toString();
                  password = edit_password.getText().toString();
  
                  Log.d(TAG, "Username:" + username);
                  Log.d(TAG, "Password:" + password);
  
                  try {
                      new Thread() {
                          public void run() {
                              try {
                                  HttpClient client = new DefaultHttpClient();
                                  HttpPost post = new HttpPost("http://10.0.2.2:8080/MyApp/login.jsp");
                                  List&lt;NameValuePair&gt; pairs = new ArrayList&lt;NameValuePair&gt;(2);
                                  pairs.add(new BasicNameValuePair("username",edit_username.getText().toString()));
                                  pairs.add(new BasicNameValuePair("password",edit_password.getText().toString()));
                                  post.setEntity(new UrlEncodedFormEntity(pairs));
                                  HttpResponse response = client.execute(post);
                                  HttpEntity httpEntity = response.getEntity();
                                  xml = EntityUtils.toString(httpEntity);
                                  Log.d("xml", ""+xml.length());   //To confirm anything is there in the "xml"
                              } catch (Exception e) {
                                  e.printStackTrace();
                              }
                          }
                      }.start();
  
                  } catch (Exception e) {
                      Log.d("xml", xml.toString());
                      Log.d("Server", e.toString());
                  }
  
                  try {
                      if (Integer.parseInt(String.valueOf(xml.charAt(10))) == 1) {  //****HERE*******
                          Toast.makeText(getApplicationContext(), "LoginSuccessful",Toast.LENGTH_SHORT).show();
                          Intent intent = new Intent(Agent_Login.this,AgentHome.class);
                          startActivity(intent);
                      } else {
                          Toast.makeText(getApplicationContext(),"Invalid Username or Password", Toast.LENGTH_SHORT).show();
                          edit_password.setText("");
                      }
                  } catch (Exception e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
          });
  
      }
  </code></pre>
  
  <p></p>
  
  <p>Now on HERE (in comment) there gives a <code>NullPointerException</code>, which is I think because the <code>xml</code> is empty.</p>
  
  <p>So, my question is how can I get the reply from the JSP in Android. I tested it on PC with an HTML form and its working absolutely fine.</p>
  
  <p>Any help would be greatly appreciated. </p>