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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:45:43+00:00 2026-06-15T13:45:43+00:00

i have done JSON parsing without using async task, it is working fine in

  • 0

i have done JSON parsing without using async task, it is working fine in gingerbread(2.3)
but when i am running the same project on ICS(ice cream sandwich) application is crashing, i heard somewhere that i will have to do the parsing in asynctask but i am new to android and unable to do that can someone help me …………

here’s my JSON class :-

public class JSONfunctions {

    public static JSONObject getJSONfromURL(String url){
        InputStream is = null;
        String result = "";
        JSONObject jArray = null;

        //http post
        try{
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(url);
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();

        }catch(Exception e){
                Log.e("log_tag", "Error in http connection "+e.toString());
        }

      //convert response to string
        try{
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                }
                is.close();
                result=sb.toString();
        }catch(Exception e){
                Log.e("log_tag", "Error converting result "+e.toString());
        }

        try{

            jArray = new JSONObject(result);            
        }catch(JSONException e){
                Log.e("log_tag", "Error parsing data "+e.toString());
        }

        return jArray;
    }
}

and here’s my MAinActivity which is using JSON class :-

public class MainActivity extends ListActivity {

    Context context;
    ArrayList<String> contentList,slugList;
    ArrayList<HashMap<String, String>> mylist;
    JSONObject json;
    JSONArray  latest;
    ImageView bck;
    String shareUrl;

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

        bck = (ImageView) findViewById(R.id.bckbtn);
        mylist = new ArrayList<HashMap<String, String>>();
        contentList=new ArrayList<String>();
        slugList=new ArrayList<String>();
        json = JSONfunctions.getJSONfromURL("http://madhuridixit-nene.com/wp/?json=get_category_posts&slug=latest");
        context=this;

        try{

            latest = json.getJSONArray("posts");

            for(int i=0;i<latest.length();i++){                     
                HashMap<String, String> map = new HashMap<String, String>();    
                JSONObject e = latest.getJSONObject(i);

                String name = e.getString("title_plain");
                String content = e.getString("content");
                contentList.add(content);
                String chng = "&#8211;";
                String  fnl_Str = name.replace(chng, "");
                String slug = e.getString("slug");
                slugList.add(slug);
                map.put("id",  String.valueOf(i));
                map.put("name", fnl_Str);
                map.put("date", e.getString("date"));
                shareUrl ="http://madhuridixit-nene.com/latest/post/";

                mylist.add(map);            
            }       
        }catch(JSONException e)        {
            Log.e("log_tag", "Error parsing data "+e.toString());
        }

        ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.activity_latest_tab, 
                new String[] { "name"}, 
                new int[] { R.id.item_title});

        setListAdapter(adapter);

        final ListView lv = getListView();
        lv.setTextFilterEnabled(true);  
        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              

                /*  HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);   */              
                //Toast.makeText(Main.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show();
                Intent intent=new Intent(context,WebViewActivity.class);
                intent.putExtra("content", contentList.get(position));
                intent.putExtra("shareUrl", shareUrl+slugList.get(position));
                intent.putExtra("tab_value", 1);
                startActivity(intent);

            }
        });


}

plz help me to get this working using AsyncTask …….

  • 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-15T13:45:43+00:00Added an answer on June 15, 2026 at 1:45 pm

    yes finally i have done it thanks for all the ideas ……

    I have created another class for asynctask like this :-

    class MyAsyncTask extends AsyncTask> > {
    ArrayList> mylist = new ArrayList>();

        @Override
        protected ArrayList<HashMap<String, String>> doInBackground(
                String... params) {
            // TODO Auto-generated method stub
    
            mylist = new ArrayList<HashMap<String, String>>();
            contentList=new ArrayList<String>();
            slugList=new ArrayList<String>();
            json = JSONfunctions.getJSONfromURL("http://madhuridixit-nene.com/wp/?json=get_category_posts&slug=latest");
    
    
            try{
    
                latest = json.getJSONArray("posts");
    
                for(int i=0;i<latest.length();i++){                     
                    HashMap<String, String> map = new HashMap<String, String>();    
                    JSONObject e = latest.getJSONObject(i);
    
                    String name = e.getString("title_plain");
                    String content = e.getString("content");
                    contentList.add(content);
                    String chng = "&#8211;";
                    String  fnl_Str = name.replace(chng, "");
                    String slug = e.getString("slug");
                    slugList.add(slug);
                    map.put("id",  String.valueOf(i));
                    map.put("name", fnl_Str);
                    map.put("date", e.getString("date"));
                    shareUrl ="http://madhuridixit-nene.com/latest/post/";
    
                    mylist.add(map);            
                }       
            }catch(JSONException e)        {
                Log.e("log_tag", "Error parsing data "+e.toString());
            }
            showProgress.setVisibility(View.VISIBLE);
            return mylist;
        }
    
        @Override
        protected void onPostExecute(ArrayList<HashMap<String, String>> result) {
            ListAdapter adapter = new SimpleAdapter(LAtestTab.this, result , R.layout.activity_latest_tab, 
                    new String[] { "name" }, 
                    new int[] { R.id.item_title});
            LAtestTab.this.setListAdapter(adapter);// If Activity extends ListActivity
            final ListView lv = getListView();
            lv.setTextFilterEnabled(true);
            showProgress.setVisibility(View.GONE);
            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
    
    
                    Intent intent=new Intent(context,WebViewActivity.class);
                    intent.putExtra("content", contentList.get(position));
                    intent.putExtra("shareUrl", shareUrl+slugList.get(position));
                    intent.putExtra("tab_value", 1);
                    startActivity(intent);
    
                }
            });
    
        }
    
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            showProgress.setVisibility(View.VISIBLE);
        }
    
        @Override
        protected void onProgressUpdate(Integer... values) {
            // TODO Auto-generated method stub
    
            super.onProgressUpdate(values);
            showProgress.setVisibility(View.VISIBLE);
        }
    
    
    
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done JSON parsing earlier but this one is not working for me.
I am using google Api for custom search and have done the json Parsing.
I have recently started parsing JSON documents using SBJSON Parser, and I am able
I have created login demo.I am parsing username and password using JSON parser which
I have done strace on my multi-threaded c++ application running on linux after couple
My task is to parse some JSON which was created by running an XML
I am retrieving a string of values from json url. I have done it
I've got this parsing operation that currently works fine, but I've started to notice
I'm working on a little Android project in java, I'm using the webapi of
Why JSON? I have done some tests today, and the request time for both

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.