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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:44:33+00:00 2026-06-16T03:44:33+00:00

So i’m trying to implement AsyncTask on my NewsParser and i thought i got

  • 0

So i’m trying to implement AsyncTask on my NewsParser and i thought i got it, but i can’t run the activity, i get the following errors on LogCat:

12-11 16:15:24.572: E/AndroidRuntime(992): FATAL EXCEPTION: main
12-11 16:15:24.572: E/AndroidRuntime(992): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.igestao/com.example.igestao.Noticias}: java.lang.NullPointerException
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.os.Looper.loop(Looper.java:137)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.ActivityThread.main(ActivityThread.java:4340)
12-11 16:15:24.572: E/AndroidRuntime(992):  at java.lang.reflect.Method.invokeNative(Native Method)
12-11 16:15:24.572: E/AndroidRuntime(992):  at java.lang.reflect.Method.invoke(Method.java:511)
12-11 16:15:24.572: E/AndroidRuntime(992):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-11 16:15:24.572: E/AndroidRuntime(992):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-11 16:15:24.572: E/AndroidRuntime(992):  at dalvik.system.NativeStart.main(Native Method)
12-11 16:15:24.572: E/AndroidRuntime(992): Caused by: java.lang.NullPointerException
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.AlertDialog.<init>(AlertDialog.java:98)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.ProgressDialog.<init>(ProgressDialog.java:77)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.ProgressDialog.show(ProgressDialog.java:110)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.ProgressDialog.show(ProgressDialog.java:99)
12-11 16:15:24.572: E/AndroidRuntime(992):  at com.example.igestao.Noticias$DownloadFilesTask.onPreExecute(Noticias.java:73)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.os.AsyncTask.execute(AsyncTask.java:511)
12-11 16:15:24.572: E/AndroidRuntime(992):  at com.example.igestao.Noticias.onCreate(Noticias.java:58)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.Activity.performCreate(Activity.java:4465)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-11 16:15:24.572: E/AndroidRuntime(992):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
12-11 16:15:24.572: E/AndroidRuntime(992):  ... 11 more

This is what i got on my MainActivity:

public class Noticias extends ListActivity {

static final String URL = "http://loc.grupolusofona.pt/index.php/?format=feed";
static final String KEY_ITEM = "item"; // parent node
static final String KEY_TITLE = "title";
static final String KEY_DESC = "description";
static final String KEY_LINK = "link";
static final String KEY_PUBDATE = "pubDate";
ProgressDialog progressDialog;
ArrayList<HashMap<String, Spanned>> menuItems = new ArrayList<HashMap<String, Spanned>>();
private DownloadFilesTask download;

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

    download = new DownloadFilesTask(null);
    download.execute();
}



private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
    private Context context;
    public DownloadFilesTask (Context context){
        this.context = context;
    }

    protected void onPreExecute() {
        progressDialog = ProgressDialog.show(context, "Loading1", "Loading2", true);
    }

    protected Long doInBackground(URL... urls) {

        XMLParser parser = new XMLParser(); 
        String xml = parser.getXmlFromUrl(URL);
        Document doc = parser.getDomElement(xml); 
        NodeList nl = doc.getElementsByTagName(KEY_ITEM);



        String data[] = new String[nl.getLength()];
        for (int i = 0; i < nl.getLength(); i++) {

            HashMap<String, Spanned> map = new HashMap<String, Spanned>();
            Element e = (Element) nl.item(i);
            data[i] = getTagValue("pubDate", e);

            SimpleDateFormat sdf = new SimpleDateFormat("EE, dd MMM yyyy HH:mm:ss z", Locale.UK);
            Date date = null;

            try {
                date = sdf.parse(data[i]); 
                String timeOfDay = new SimpleDateFormat("HH:mm").format(date); 
                java.sql.Timestamp timeStampDate = new Timestamp(date.getTime());
                java.sql.Timestamp timeStampNow = new Timestamp((new java.util.Date()).getTime());  

                long secondDiff = timeStampNow.getTime() / 1000 - timeStampDate.getTime() / 1000;
                int minuteDiff = (int) (secondDiff / 60);
                int hourDiff = (int) (secondDiff / 3600);
                int dayDiff = daysBetween(date, new Date());
                if (dayDiff > 0) {
                    System.out.println("Há " + dayDiff + " dia(s), às " + timeOfDay); 
                    data[i] = ("Há " + dayDiff + " dia(s), às " + timeOfDay);


                } else if (hourDiff > 0) {
                    System.out.println("Há " + hourDiff + " hora(s), às " + timeOfDay);
                    data[i] = ("Há " + hourDiff + " hora(s), às " + timeOfDay);


                } else if (minuteDiff > 0) {
                    System.out.println("Há " + minuteDiff + " minuto(s), às " + timeOfDay);
                    data[i] = ("Há " + minuteDiff + " minuto(s), às " + timeOfDay);


                } else if (secondDiff > 0) {
                    System.out.println("Há " + secondDiff + " segundo(s), às " + timeOfDay);
                    data[i] = ("Há " + secondDiff + " segundo(s), às " + timeOfDay);

                }
            } catch (ParseException e1) {
                e1.printStackTrace();
            } catch (java.text.ParseException e1) {
                e1.printStackTrace();
            }


            map.put(KEY_TITLE, Html.fromHtml(parser.getValue(e, KEY_TITLE)));
            map.put(KEY_DESC, Html.fromHtml(parser.getValue(e, KEY_DESC)));
            map.put(KEY_PUBDATE, Html.fromHtml(data[i]));
            map.put(KEY_LINK, Html.fromHtml(parser.getValue(e, KEY_LINK)));

            menuItems.add(map);

        }//endFOR
        return null;

    }

    protected void onPostExecute(Long result) {
        progressDialog.dismiss();
        adapter_listview();


        //onClick gets URL from ListView and opens it
        ListView lv = getListView();
        lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            String link = ((TextView) view.findViewById(R.id.link)).getText().toString();
            Intent in = new Intent(Intent.ACTION_VIEW);
            in.setData(Uri.parse(link));
            startActivity(in);

        }
    });


    }
}








private static String getTagValue(String sTag, Element e) { 

    NodeList nlList = e.getElementsByTagName(sTag).item(0).getChildNodes();

    Node nValue = (Node) nlList.item(0);

    return nValue.getNodeValue();

}

public static int daysBetween(Date startDate, Date endDate) { 

    int daysBetween = 0;
    while (startDate.before(endDate)) {
        startDate.setTime(startDate.getTime() + 86400000);
        daysBetween++;
    }
    return daysBetween;

}

public void adapter_listview(){

    ListAdapter adapter = new SimpleAdapter(this, menuItems, R.layout.linhafeed, 
            new String[] { KEY_TITLE, KEY_DESC, KEY_PUBDATE, KEY_LINK },
            new int[] { R.id.title, R.id.desc, R.id.pub, R.id.link });


    setListAdapter(adapter);

}
}

Could someone please tell me what i’m doing wrong ?
I’ve been through the Tutorials on AsyncTask, but to no effect here.
Thanks for your time.

  • 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-16T03:44:34+00:00Added an answer on June 16, 2026 at 3:44 am

    download = new DownloadFilesTask(null);

    In the above line of code you are passing null, that shouldNot be done.

    – Pass Activity_Name.this instead of null.

    Eg:

    download = new DownloadFilesTask(Noticias.this);
    download.execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.