Note that there are some explanatory texts on larger screens.

plurals
  1. POReading a string echoed from PHP into java?
    primarykey
    data
    text
    <p>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.</p> <pre><code> 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());} </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload