2

I have an android app which calls upon a php script, the php script simply does this: echo "1" if true, echo "2" if false.

The android app buffers the script using:

 InputStream inputStream = httpURLConnection.getInputStream();
    BufferedReader bufferedReader = new BufferedReader(new      
    InputStreamReader(inputStream, "iso-8859-1"));

   while ((line = bufferedReader.readLine()) != null) {
                    result += (line);
                }

The problem I am having is that, my android app then compares the variable result with if(result == "1")

But for some reason, the comparison always goes to the "else" and never hits the "if"

I have made sure my PHP script echos just "1", also made an alertdialog box to confirm that "1" is being returned to the variable "result"

Is it because of my inputstream? I am quite stumpped at the moment

EDIT: Also want to affirm that this is not a duplicate question to "how do you compare strings in java." My question is regarding comparing a PHP echo output, to Java's inputstream.

alex067
  • 3,159
  • 1
  • 11
  • 17
  • a simple bit of debugging e.g. a `System.out.println` statement will allow you to see what the value really is – Scary Wombat Mar 29 '18 at 01:24
  • BTW, you state *my android app then compares the variable result with if(result == "1")* -- That is why I marked this a duplicate. If that is not the case, then edit your question, and create a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve) – Scary Wombat Mar 29 '18 at 01:26
  • I have used an alertdialog box to post the results, and confirmed that my inputstreamer is assigning the value "1" to my variable "result" I have also tried forcing return and newlines in the comparison, used the .equals just incase, but it always reverts to the else. – alex067 Mar 29 '18 at 01:29
  • so [Please add a minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve) and what is an `alertdialog` ? – Scary Wombat Mar 29 '18 at 01:30
  • an alertdialog is an android output function, similar to an echo or system.out.print – alex067 Mar 29 '18 at 01:36

0 Answers0