-2

I'm letting users retrieve their forgotten password by webservice. all are function is performing json give success output but after this debugger is not going in try (if else) condition...

my forgetpass response:

{
status: "Success" 
msg: "Password has been sent your Email_id , Please check it.."
}

try/catch:

params.add(new BasicNameValuePair("email",Email));

JSONObject json = jsonParser.makeHttpRequest(url,"POST", params);
Log.d("Create Response", json.toString());
try{
    String status=json.getString(TAG_SUCCESS);
    if(status=="TAG_SUCCESS"){

        Toast.makeText(ForgetPassWord.this,"Password has been sent your Email_id , Please check it..", Toast.LENGTH_LONG).show();
        finish();
    }else{
        Toast.makeText(ForgetPassWord.this,"Please Enter Correct E-Mail", Toast.LENGTH_LONG).show();
    }
}catch(JSONException e) {
    e.printStackTrace();
}
return null;
BenMorel
  • 34,448
  • 50
  • 182
  • 322
user3596211
  • 65
  • 1
  • 7

2 Answers2

1

use equals() for String Comparison

like

status.equals("Success")

Edit:

Change it like below

  private static final String TAG_SUCCESS="status";// Because  status is the key

String status = json.getString(TAG_SUCCESS);
Amit Gupta
  • 8,914
  • 1
  • 25
  • 33
  • thnks for help amit ...but still not working....String status=json.getString(TAG_SUCCESS);.aftr this statement debuggr move on (catch).... – user3596211 May 08 '14 at 11:07
  • @user3596211 did you get the response successfully. What is the value for "TAG_SUCCESS" that you define. Json key always be case sensitive. – Amit Gupta May 08 '14 at 11:10
  • i m getting response successfully from json private static final String TAG_SUCCESS="Success";.......this is define in class ......... – user3596211 May 08 '14 at 11:15
  • @user3596211 TAG_SUCCESS="Success"; this is wrong. b'coz the key string is "status". Check my updated answer. – Amit Gupta May 08 '14 at 11:18
  • thnku so much amit bro ...its working ..aftr this how to send email to given email andress.......plzzz tell me about how to code plzzz – user3596211 May 08 '14 at 11:30
  • @user3596211 if its working for you, please accept my answer. And create a new thread for new question. – Amit Gupta May 08 '14 at 11:43
  • aftr successing toast msg is not displaying in this .....getting error unfortunatally app has stoped ....error – user3596211 May 08 '14 at 12:08
1

Try this

try {

            if (json.has((TAG_SUCCESS))) {
                String status = json.getString(TAG_SUCCESS);
                if (status.equals(TAG_SUCCESS)) {

                    Toast.makeText(
                            ForgetPassWord.this,
                            "Password has been sent your Email_id , Please check it..",
                            Toast.LENGTH_LONG).show();
                    finish();
                }

                else {
                    Toast.makeText(ForgetPassWord.this,
                            "Please Enter Correct E-Mail",
                            Toast.LENGTH_LONG).show();
                }
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
Shini
  • 573
  • 4
  • 11