1
if(jsonArray.getJSONObject(i).get("SECNO").toString()!=null && jsonArray.getJSONObject(i).get("SECNO").toString().trim()!="")
                        appointment.mSecNo =Integer.parseInt(jsonArray.getJSONObject(i).get("SECNO").toString());
                    else
                        appointment.mSecNo = -1;

In the previouse lines, when the value of jsonArray.getJSONObject(i).get("SECNO").toString() equales to '' it doesn't be caught by the if statement ..

and I get this error message .. can't parse '' to integer

Adham
  • 63,550
  • 98
  • 229
  • 344

3 Answers3

2

Don't use == or != to compare strings in Java - it only compares the references, not the contents of the strings. Also, I doubt that toString would ever return null. I suspect you want:

Foo x = jsonArray.getJSONObject(i).get("SECNO");
if (x != null && x.toString().trim().length() > 0)

(I don't know what the type of jsonArray.getJSONObject(i).get("SECNO") would be, hence the Foo.)

In this particular case I've used length() > 0 to detect a non-empty string - but for more general equality, you'd want to use equals, so an alternative is:

if (x != null && !x.toString().trim().equals(""))
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

Don't compare Strings with ==

See: Java comparison with == of two strings is false? , Java String.equals versus ==

Community
  • 1
  • 1
Dunes
  • 37,291
  • 7
  • 81
  • 97
0

Why not just,

int appointment.mSecNo = -1;

try {
    appointment.mSecNo = Integer.parseInt(jsonArray.getJSONObject(i).get("SECNO").toString());
}catch(Exception e) {
    log.error(" your error message ");
}
Rosdi Kasim
  • 24,267
  • 23
  • 130
  • 154