I am trying to use the following code to retrieve a response from a server echoed through PHP. The string compare methods compareTo() and (...).equals(..) do not act properly when this code is executed. I have tried all sorts of options and I'm convinced that in spite of appearing to convert the response to string format, "responseText" does not have the typical string properties. If I have 3 string literal statements, one of which is echoed from findUser.php. How can I read it into java in a way that will allow me to determine the contents of the string as i am trying to do here? I have found a lot of discussion about needing to create BufferedReader object, but I do not understand how to implement that. If someone would please lay out the steps for me, I would be very appreciative.
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(".../findUser.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
final String responseText = EntityUtils.toString(response.getEntity());
if(responseText.compareTo("Not Registered") == 0 || responseText.compareTo("Error") == 0) {
Log.i("KYLE","TRUE");
// DISPLAY ERROR MESSAGE
TextView loginError = (TextView)findViewById(R.id.loginErrorMsg);
loginError.setVisibility(View.VISIBLE);
loginError.setText(responseText);
}
else {
GlobalVars.username = userEmail;
Login.this.finish();
Intent intent = new Intent(Login.this,Purchase.class);
startActivity(intent);
}
catch(Exception e) {Log.e("log_tag", "Error in http connection"+e.toString());}
}
responseText?loginError.setText(responseText)- would've been nice if he included the output of course...compareTo()method doesn't work properly, which I thought meant that the corresponding block of code is never executed. I'd like to see the value logged before the conditionals.