0

this is a basic knowledge but I get frustrated after 3 hours of trying. I am running codes in Android Studio and I just want to compare the result of 2 strings This is my codes

String result=stringBuilder.toString();
        String wanted="SUCCESS";

        if(result.equalsIgnoreCase("SUCCESS"))
        {
            Log.d("RESULT","FINALLY 1");
        }
        else if(result.equals("SUCCESS")) {
            Log.d("RESULT", "FINALLY 2");
        }
        else if(result=="SUCCESS")
        {
            Log.d("RESULT","FINALLY 3");

        }
        else if("SUCCESS".equals(result))
        {
            Log.d("RESULT","FINALLY 4");
        }
        else if(result.equals(wanted))
        {
            Log.d("RESULT","FINALLY 5");
        }
        else
        {
            Log.d("RESULT",result);
        }

I have tried every options available on webs but I got the same results and you can see that var "result" is "SUCCESS"

  11-11 23:31:01.477    8116-8152/com.example.asus.ucomm D/RESULT﹕ SUCCESS

What did I do here that get errors from just comparing strings? Am I too tired until I missed something? Please help.

//EDIT I get stringBuilder.toString() to get the response from my PHP file. This is the last code that checks the database

if(isset($_GET['user']))
{
    $findFriend=$_GET['user'];
    $sql = "SELECT * FROM username WHERE pin='$findFriend'";
}
$result = $conn->query($sql);

if ($result->num_rows > 0) 
{
    echo "SUCCESS";
}
else echo "NOT FOUND";

//EDIT 2 The result before trim() is

 11-12 00:07:56.057    6000-6036/com.example.asus.ucomm D/RESULT﹕ +SUCCESS
+

I thought that it ran out of space. But it had /n

  • Which value you got in **result** variable? – Nitin Karande Nov 11 '16 at 16:49
  • 1
    Is no space in start or end `result`? Try with `trim()` or `Log.d("RESULT","-"+result+"-"); ` – Bills Nov 11 '16 at 16:52
  • @Blackbelt I know it has been asked but I get errors from mine. I know that you should use .equals() in Java. But It just don't work. I have also used Objects.equals() and it don't work either. I just need help here. – Dhani Himawan Nov 11 '16 at 16:58
  • @Nitin I get from response from server. I echo "SUCCESS" if the data existed on my database – Dhani Himawan Nov 11 '16 at 16:59
  • @Blackbelt And also I just add the detail that I get stringBuilder.toString() to get response from PHP file – Dhani Himawan Nov 11 '16 at 17:05
  • I suggested to Compare only one string **result.equals("SUCCESS")** and print the your **Log.d("RESULT",result);** . Check the print value of result response. It will work – Nitin Karande Nov 11 '16 at 17:06
  • 1
    @Bills DUUDEE!! YES THAT IS IT!! I tried it earlier I get **11-12 00:07:56.057 6000-6036/com.example.asus.ucomm D/RESULT﹕ +SUCCESS +**. There is a new line and it move to below. I thougt that it ran out of space. Answer it and I will accept it. Thanks so much – Dhani Himawan Nov 11 '16 at 17:09
  • This question is marked as duplicate, can't let me answer :( – Bills Nov 11 '16 at 17:47

0 Answers0