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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:02:23+00:00 2026-06-17T14:02:23+00:00

I am trying to implement Async Task in this class but the thing is

  • 0

I am trying to implement Async Task in this class but the thing is that I am calling getInputStream function in my program which is returning a value and I am not sure Where to put it. Where should I define getInputStream in my async task?
I am getting the below exception

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity      com.sparkplug.xxxx}: java.lang.NullPointerException

Below is my main class:

public class abcreaderextends ListActivity {

    ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

    parsing p=new parsing();

        @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_awsreader);
        ((PullToRefreshListView) getListView())
                .setOnRefreshListener(new OnRefreshListener() {
                    public void onRefresh() {
                        // Do work to refresh the list here.
                        new GetDataTask().execute();
                    }
                });
        InputStreamOperation in= new InputStreamOperation();

        in.execute();

        //p.parse();

        for (int i = 0; i < p.headlines.size(); i++) {
            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();
            // adding each child node to HashMap key => value
            map.put("title", p.headlines.get(i));
            map.put("dcdate", p.lstDate.get(i));
            map.put("description", p.description.get(i));
            // adding HashList to ArrayList
            menuItems.add(map);
        }

                ListAdapter rssFeedSection = new SimpleAdapter(this, menuItems,
                R.layout.list_item, new String[] { "title", "dcdate",
                        "description" }, new int[] { R.id.name, R.id.date1,
                        R.id.desc });
        setListAdapter(rssFeedSection);
    }

    class GetDataTask extends AsyncTask<Void, Void, String[]> {
        @Override
        protected void onPostExecute(String[] result) {
            // **menuItems.addFirst("Added after refresh...");
            // Call onRefreshComplete when the list has been refreshed.
            ((PullToRefreshListView) getListView()).onRefreshComplete();
            super.onPostExecute(result);
        }

        @Override
        protected String[] doInBackground(Void... params) {
            // TODO Auto-generated method stub
            return null;
        }
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Uri uri = Uri.parse((String) p.links.get(position));
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }
}

This is my parsing class:
public class parsing {
List headlines;
List links;
List description;
List lstDate;
List newDate;
//String a,b,c,d;
public InputStream getInputStream(URL url) {
try {
return url.openConnection().getInputStream();
} catch (IOException e) {
return null;
}
}

    public HashMap<String, ArrayList<String>> parse() {

        // Initializing instance variables
        headlines = new ArrayList<String>();
        links = new ArrayList<String>();
        description = new ArrayList<String>();
        lstDate = new ArrayList<String>();
        try {
            URL url = new URL(
                    "http://feeds.feedburner.com/xxxx");
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            factory.setNamespaceAware(false);
            XmlPullParser xpp = factory.newPullParser();
            // We will get the XML from an input stream
            xpp.setInput(getInputStream(url), "UTF_8");
            int i = 0;
            boolean insideItem = false;
            // Returns the type of current event: START_TAG, END_TAG, etc..
            int eventType = xpp.getEventType();
            int k = 0;
            while (eventType != XmlPullParser.END_DOCUMENT) {
                i++;
                // Log.i("Tag : ",xpp.getName().toString());
                // Log.i("Text : ",xpp.nextText().toString());
                if (eventType == XmlPullParser.START_TAG) {
                    Log.i("Tag : ", xpp.getName().toString());
                    // Log.i("Text : ",xpp.nextText().toString());
                    if (xpp.getName().equalsIgnoreCase("item")) {
                        insideItem = true;
                    } else if (xpp.getName().equalsIgnoreCase("title")) {
                        if (insideItem) {
                            String var = xpp.nextText().toString();
                            headlines.add(var); // extract the description of
                                                // article
                            Log.i("Title : ", var);
                            // Log.i("Count : ",i+"");
                        }
                    } else if (xpp.getName().equalsIgnoreCase("description")) {
                        if (insideItem) {
                            String desc = xpp.nextText().toString();
                            description.add(desc); // extract the description of
                                                    // article
                            Log.i("Desc : ", desc);
                        }
                    } else if (xpp.getName().equalsIgnoreCase("dc:date")) {
                        if (insideItem) {
                            String strDate = xpp.nextText().toString();

                            System.out.println("rahul"+strDate.substring(0,10));
                            //lstDate = Arrays.asList(arr[k].substring(0,10));
                            lstDate.add(strDate.substring(0,10));
                            System.out.println("lstDate"+lstDate);
                            k = k+1;
                            Log.i("Date : ", strDate);
                        }
                    } else if (xpp.getName().equalsIgnoreCase("link")) {
                        if (insideItem)
                            links.add(xpp.nextText()); // extract the link of
                                                        // article
                    }
                } else if (eventType == XmlPullParser.END_TAG
                        && xpp.getName().equalsIgnoreCase("item")) {
                    insideItem = false;
                }
                eventType = xpp.next(); // move to next element
            }// While end
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        HashMap<String, ArrayList<String>> alllists = 
                                        new HashMap<String, ArrayList<String>>();
        alllists.put("headlines",(ArrayList<String>) headlines);
        alllists.put("links",(ArrayList<String>) links);
        alllists.put("description",(ArrayList<String>) description);
        alllists.put("lstDate",(ArrayList<String>) lstDate);

        return alllists;
        }
}

and this one is my InputStreamOperation class:
public class InputStreamOperation extends AsyncTask>> {

@Override
protected void onPreExecute() {
// show progress bar here(have not used any progress bar)
}

@Override
protected HashMap<String, ArrayList<String>> 
                           doInBackground(Void... params) {

//call parse() method here
parsing parsingobj=new parsing();
HashMap<String, ArrayList<String>> alllists=parsingobj.parse();

return alllists;  //<<< retun final result from here

}      

@Override
protected void onPostExecute(HashMap<String, ArrayList<String>> result) {  
// update UI 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-17T14:02:24+00:00Added an answer on June 17, 2026 at 2:02 pm

    you will need to call getInputStream inside doInBackground method of AsyncTask as:

    First Change parse method return type to HashMap<String, String> as :

    public HashMap<String, ArrayList<String>> parse() {
    
     ///your code here...
    
    HashMap<String, ArrayList<String>> alllists = 
                                    new HashMap<String, ArrayList<String>>();
    alllists.put("headlines",headlines);
    alllists.put("links",links);
    alllists.put("description",description);
    alllists.put("lstDate",lstDate);
    
    return alllists;
    }
    

    and Create AsyncTask class as :

    private class InputStreamOperation extends 
                        AsyncTask<String, Void, HashMap<String, ArrayList<String>>> {
    
          @Override
          protected void onPreExecute() {
            // show progress bar here
          }
    
          @Override
          protected HashMap<String, ArrayList<String>> 
                                                   doInBackground(String... params) {
    
               //call parse() method here
              parsing parsingobj=new parsing();
              HashMap<String, ArrayList<String>> alllists=parsingobj.parse();
    
              return alllists;  //<<< retun final result from here
    
          }      
    
          @Override
          protected void onPostExecute(HashMap<String, ArrayList<String>> result) {  
                  // update UI here            
          }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is an async class i created that i am trying to implement a
I am trying to implement a class that can listen for incoming TCP data.
I am trying to implement a httpClient class which is an AsyncTask (otherwise I
Following this question , I am trying to implement an async method using the
I am trying to implement a thread pool that processes a task queue using
I am new to Objective C and I am trying to implement an async
I'm trying implement A* Start path finding in my games(which are written with JavaScript,
Trying to implement a search similar to here .This searches properties based on city,locality,property
I'm trying to implement this (Configuring Sockets for VoIP Usage) using this (CocoaAsyncSocket). To
I am trying to implement a RESTful API in which I have to upload

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.