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

  • Home
  • SEARCH
  • 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 8741875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:23:41+00:00 2026-06-13T11:23:41+00:00

I am a beginner in Android, and I am writing a short program to

  • 0

I am a beginner in Android, and I am writing a short program to download a JSON feed from URL and parse it. I use AsyncTask to do the downloading.

The doInBackground() part seems to work well. Then I set my breakpoint to onPostExecute(), it can even stop at parseJSON(result), and ‘result’ is showing the correct json string downloaded. But when I try to step into parseJSON(result), it will NOT step into the function correctly(either throw JSONException directly or go to some random lines within parseJSON(result)).

From DDMS log it’s not showing any valuable information as well.

How might I find what the problem is? Is it because I used onPostExecute() incorrectly, or parseJSON() has some problem?

public class MainActivity extends Activity {

    private listItem[] items;

    public class listItem {
        String title;
        String description;
        String imageHref;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        items = new listItem[50];

        new DownloadJsonFeed().execute("http://dl.dropbox.com/u/10168342/facts.json");
    }

    private class DownloadJsonFeed extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... params) {

            try {
                return downloadUrl(params[0]);
            } catch (IOException e) {
                return "Unable to retrieve json feed. URL may be invalid.";
            }
        }

        @Override
        protected void onPostExecute(String result) {
            try {
                parseJSON(result);          // Here !!!!!!
            } catch (JSONException e) {
            }
        }
    }

    private String downloadUrl(String myurl) throws IOException {
        InputStream is = null;

        try {
            URL url = new URL(myurl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setReadTimeout(10000 /* milliseconds */);
            conn.setConnectTimeout(15000 /* milliseconds */);
            conn.setRequestMethod("GET");
            conn.setDoInput(true);
            conn.connect();
            is = conn.getInputStream();

            // Convert the InputStream into a string
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            StringBuilder sb = new StringBuilder();
            String line = null;

            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            is.close();
            return sb.toString();
        } finally {
            if (is != null) {
                is.close();
            } 
        }
    }

    private void parseJSON(String feed) throws JSONException {
            JSONObject json_obj = new JSONObject(feed);
            title = json_obj.getString("title");
            String rows = json_obj.getString("rows");

            JSONArray jArray = new JSONArray(rows);
            for (int i = 0; i < jArray.length(); i++) {
                JSONObject tmp = jArray.getJSONObject(i);
                items[i].title = tmp.getString("title");
                items[i].description = tmp.getString("description");
                items[i].imageHref = tmp.getString("imageHref");
            }
    }
  • 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-13T11:23:43+00:00Added an answer on June 13, 2026 at 11:23 am

    I think you didn’t get the JSON array right. The json_obj.getString will give you an String instead an array.

    Try to change as follows:

      private void parseJSON(String feed) throws JSONException {
                JSONObject json_obj = new JSONObject(feed);
                title = json_obj.getString("title");
                String rows = json_obj.getString("rows");
    
                JSONArray jArray = json_obj.getJSONArray("rows"); //<---- change this line
                for (int i = 0; i < jArray.length(); i++) {
                    JSONObject tmp = jArray.getJSONObject(i);
                    items[i].title = tmp.getString("title");
                    items[i].description = tmp.getString("description");
                    items[i].imageHref = tmp.getString("imageHref");
                }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a beginner in Android. I use Eclipse to program my app. When I
I am a beginner at writing android apps. Can you please help me how
I am beginner in android, my requirement is to parse a plist file and
I am pure beginner to [android-eclipse],here i need to consume web services from the
I am beginner android developer.I am writing app witch write calls(incomming,outgoing,missed) to Android Calendar
I am a beginner in Android. I need to swipe only from left to
I am a beginner of android programming. I am trying to use facebook SSO,
I m beginner in android. i want to open twitter url in webview. i
I'm a beginner android programmer who is trying to set up some USB functionality
I am implementing a Database for my (beginner/Android) application. It is not clear to

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.