I'm having a hard time keeping my code clean... mainlly because all the try's and catches... I'm simple doing an HTTP request on which the response is then converted to JSON Array.. but now it's a mess of {}'s .. is there anyway to agregate all this try and catches? The code really looks bad and unreadable like this... and worst, it's executing correctly because I'm not finishing in the correct places..
nameValuePairs.add(new BasicNameValuePair("id", picId)); InputStream content = null; HttpClient httpclient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("http://www.pedroteixeira.org/ thennnow/alg_showpopup.php"); try { httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { response = httpclient.execute(httpPost); } catch (ClientProtocolException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { content = response.getEntity().getContent(); } catch (IllegalStateException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } StringBuilder sb = new StringBuilder(); String line; BufferedReader reader; try { reader = new BufferedReader(new InputStreamReader(content, "UTF-8")); while ((line = reader.readLine()) != null) { sb.append(line); String pic_values = sb.toString(); try { picvalues = new JSONArray(pic_values); } catch (JSONException e) { // TODO Auto-generated catch block picvalues = new JSONArray(""); // just so it's not null. } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en