Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8089159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:19:16+00:00 2026-06-05T19:19:16+00:00

public String getBrotherHood() throws Exception{ client = new DefaultHttpClient(); get = new HttpGet(uri); res

  • 0
public String getBrotherHood() throws Exception{        
    client = new DefaultHttpClient();
    get = new HttpGet(uri);
    res = client.execute(get);
    sl = res.getStatusLine();
    sCode = sl.getStatusCode();
    if(sCode==200)
    {
        try{
            reader = new BufferedReader(new InputStreamReader(res.getEntity().getContent()));
            readBuffer = new StringBuffer();
            while((nl = reader.readLine())!=null){
                readBuffer.append(nl);
            }
            reader.close();
        }finally{
            if(reader !=null)
            {
                try{
                    reader.close();
                }catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
            }
        }
    }
    return readBuffer.toString();       
  }
}

I have this code, is this the proper way of writing it, or should i need to follow any coding pattern or standards ??

Please give me some suggestions coz im not to Android Coding.

Update:

public class JSONData {

public ArrayList<String> getBrotherHoodJSON() throws JSONException,IOException,Exception{
    ArrayList<String> item = new ArrayList<String>();
    JSONArray jA = new JSONArray(getBrotherHood());

    for(int i=0; i<jA.length(); i++)
    {
        JSONObject jO = jA.getJSONObject(i);
        String n = jO.getString("name");
        item.add(n);
        Log.i("JsonData:",jO.getString("name"));
    }

    return item;
}   

public String getBrotherHood() throws Exception{    
    BufferedReader in = null;
    String data= null;
    HttpClient client = new DefaultHttpClient();
    URI uri = new URI("http://fahidmohammad.in/demo/Android/api.php?user=fah");
    HttpGet get = new HttpGet();
    get.setURI(uri);
    HttpResponse res = client.execute(get);
    StatusLine sl = res.getStatusLine();
    int sCode = sl.getStatusCode();
    if(sCode==200)
    {
        try{
            in = new BufferedReader(new InputStreamReader(res.getEntity().getContent()));
            StringBuffer sb = new StringBuffer();
            String nl;
            while((nl = in.readLine())!=null){
                sb.append(nl);
            }
            in.close();
            data = sb.toString();
            Log.i("Raw Data:",data);
            return data;
        }finally{
            if(in !=null)
            {
                try{
                    in.close();
                    return data;
                }catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
            }
        }
    }
    return data;        
}

Here is the updated version the same code.
Taken care of all the mentioned issues.

And also its working like a charm, but don’t know the stability of it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:19:17+00:00Added an answer on June 5, 2026 at 7:19 pm

    You obviously have declared all variables outside your method even though they seem to be used only within this method. That makes no sense. It prevents several objects from being garbage collected. You better move the declaration into the method.

    And the declaration throws Exception doesn’t make much sense either. You are better of if you either declare a specific exception that could likely occur or if you convert all unlikely exceptions into RuntimeException so you don’t need to declare them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public string[] SearchForMovie(string SearchParameter) { WebClientX.DownloadDataCompleted += new DownloadDataCompletedEventHandler(WebClientX_DownloadDataCompleted); WebClientX.DownloadDataAsync(new Uri( http://www.imdb.com/find?s=all&q=ironman+&x=0&y=0 )); string
public class SomePropertyClass{ public string VarA{get;set;} public string VarB{get;set;} } SomePropertyClass v1 = new
public String[] getValue(String keyName) { ArrayList arraylist = (ArrayList) value.get(getKey(keyName)); String[] valueArray = new
public class Song { public string Genre { get; protected set; } public string
public class Mailing { public string To { get; set; } public string AttachmentPath
public class Account { public string Username { get { return Username; } set
Public class AbcViewModel { public string native{get; set;} public string other{get; set;} public List<AbcViewModel>
public class ReflectionBase { public String ParentProperty1 { get; set; } public String ParentProperty2
public class LearnerInfo { public string Id { get; set; } public string Name
lot__no is a public string Dim myDelims As String() = New String() {<beginning of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.