Issue
I simply have an AsyncTask that use a listener to communicate with the main activity. Where the response is arrived , and the first Toast will been shown with correct values. The problem is that in try catch I can recover the values. So if or switch don't work anymore.
@Override
public void OnAsyncTaskComplete(String response) {
Toast.makeText(getContext(),((ActivityLogin) getActivity()).choiceButton+" result: "+response, Toast.LENGTH_LONG).show();
try {
JSONObject obj = new JSONObject(response);
String objservice = obj.getString("service");
String objstatuCode = obj.getString("status-code");
String objdescription = obj.getString("status-description");
JSONObject result = obj.getJSONObject("result");
if(!objstatuCode.equals("200") || objstatuCode.equals(null)){
Toast.makeText(getContext(), objstatuCode+"", Toast.LENGTH_SHORT).show();
return;
} else {
Toast.makeText(getContext(), objstatuCode+"", Toast.LENGTH_SHORT).show();
return;
}
} catch (JSONException e){
e.printStackTrace();
}
}
Solution
I assume, You getting JSONException
.
Why?
Thrown to indicate a problem with the JSON API
Problem coming from
String objstatuCode = obj.getString("status-code");
JSONObject result = obj.getJSONObject("result");
Your JSON VALUE (KEY=status-code)
is int
. You should rectify that.
It must be
int objstatuCode = obj.getInt("status-code");
String result = obj.getString("result");
Then
if(objstatuCode!=200){
Toast.makeText(getContext(), objstatuCode+"", Toast.LENGTH_SHORT).show();
return;
} else {
Toast.makeText(getContext(), objstatuCode+"", Toast.LENGTH_SHORT).show();
return;
}
Answered By - IntelliJ Amiya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.