android - program stuck at getResponseCode() -
i writing android application need parse json url . program freezes after getresponsecode() , displaying no error. debugger displays " application running". program stuck. code :
httpurlconnection c = null; try { url u = new url(url); c = (httpurlconnection) u.openconnection(); c.setrequestmethod("get"); c.setrequestproperty("content-length", "0"); c.setconnecttimeout(1000); c.setusecaches(false); c.setallowuserinteraction(false); c.connect(); int status = c.getresponsecode(); system.out.println(status); switch (status) { case 200: case 201: bufferedreader br = new bufferedreader(new inputstreamreader(c.getinputstream())); stringbuilder sb = new stringbuilder(); string line; while ((line = br.readline()) != null) { sb.append(line+"\n"); } br.close(); string json = sb.tostring(); try { jarray = new jsonarray(json); jobj = new jsonobject[jarray.length()]; //get each object json array for(int i=0;i<jarray.length();i++) { jobj[i] = jarray.getjsonobject(i); } } catch (jsonexception e) { log.e("json parser", "error parsing data " + e.tostring()); }catch (exception e){ log.e("something wrong",""+e.tostring()); } } } catch (malformedurlexception ex) { logger.getlogger(getclass().getname()).log(level.severe, null, ex); } catch (ioexception ex) { logger.getlogger(getclass().getname()).log(level.severe, null, ex); } { if (c != null) { try { c.disconnect(); } catch (exception ex) { logger.getlogger(getclass().getname()).log(level.severe, null, ex); } } }
it works other urls except one. idea why might happening ?
in case server issue .
Comments
Post a Comment