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 8259101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:46:47+00:00 2026-06-08T02:46:47+00:00

Im making an Android application, and for that i have to get JSON content

  • 0

Im making an Android application, and for that i have to get JSON content from a URL (which is output by some python script).

I found a method for that on SO, but i can’t get it to work. This is the code:

public String webGet(String URL) throws Exception  
{ 
    BufferedReader in = null; 
    try  
    { 
        HttpClient client = new DefaultHttpClient(); 
        client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "android"); 

        HttpGet request = new HttpGet();
        request.setHeader("Content-Type", "text/html; charset=utf-8"); 
        request.setURI(new URI(URL)); 

        // Crashes after executing this line
        HttpResponse response = client.execute(request); 

        in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 

        StringBuffer sb = new StringBuffer(""); 
        String line = ""; 

        String NL = System.getProperty("line.separator"); 
        while ((line = in.readLine()) != null)  
        { 
            sb.append(line + NL); 
        } 
        in.close(); 
        String page = sb.toString();

        //System.out.println(page); 
        return page; 
    }  
    finally  
    { 
        if (in != null)  
        { 
            try  
            { 
                in.close(); 
            }  
            catch (IOException e)     
            { 
                Log.d("BBB", e.toString()); 
            } 
        } 
    } 
}

This crash happends after this line:

HttpResponse response = client.execute(request);

It then simply jumps to the finally part and all i can get from the exception message is that something was null. That’s all it says.

Anyone any idea what the problem could be?


Screenshot of the Exception description:

enter image description here

  • 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-08T02:46:53+00:00Added an answer on June 8, 2026 at 2:46 am

    You cannot perform network actions from your ‘main’ thread within certain versions of Android. It’s to ensure your app is still responsive to the end user, even if it does some blocking, network action that takes a long time.

    You would need to do that action another thread.

    Unable to connect to FTP in Android

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

Sidebar

Related Questions

I'm making an Android application that has to read some values from a JSON
I am making an android application that loads files from a directory on the
I am making an android application, which takes an image from camera and then
I am making an android application in which i have five items in a
I am making an android application in which I have put 10 images and
I'm making an android application that plays music. When I run it, I get
I have an Android project in which I get a token from the server
I am making an android application which has a main activity and several other
I am making an Android application. In my application, I have to find the
So, I'm making my first Android application, which basically contains ~250 .txt files in

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.