0
votes

I am attempting to show an indeterminate ProgressDialog while grabbing an RSS feed. I get the dialog to pop, but as soon as the results are returned, I get a force close. My suspicion is that the adapter is populated and goes to update the UI. The code is below. Is my suspicion correct?

        public void getRSS(String rss)
    {

        new GetRSS().execute(rss);

    }
    private class GetRSS extends AsyncTask<String, Void, Void>
    {
        private ProgressDialog Dialog = new ProgressDialog(View2.this);

        protected void onPreExecute() {

            Dialog.setMessage("Please wait...");
            Dialog.show();
        }

        protected void onPostExecute(Void nothing)
        {
            Dialog.dismiss();
        }

        protected Void doInBackground(String... rss) {
        URL feedUrl;
        try
            {
                feedUrl = new URL(rss[0]);

                SyndFeedInput input = new SyndFeedInput();
                SyndFeed feed = input.build(new XmlReader(feedUrl));
                List entries = feed.getEntries();

                Iterator iterator = entries.listIterator();
                while (iterator.hasNext())
                    {
                        SyndEntry ent = (SyndEntry) iterator.next();
                        String title = ent.getTitle();
                        //String uri = ent.getUri();
                        //d.add(uri);

                        SyndContent content = (SyndContent)ent.getContents().get(0);
                        d.add(content.getValue());
                        adapter.add(title);
                    }
                adapter.notifyDataSetChanged();
            }
        catch (MalformedURLException e)
            {
                e.printStackTrace();
            }
        catch (IllegalArgumentException e)
            {
                e.printStackTrace();
            }
        catch (FeedException e)
            {
                e.printStackTrace();
            }
        catch (IOException e)
            {
                e.printStackTrace();
            }
        return null;
        }
    }
    */

Here's the stack dump -- clearly the call to notify is the issue. Now I'm just having trouble figuring out where to call notify:

01-22 12:02:28.701: ERROR/WindowManager(571): Activity com.digthisband.dtb.jg.View2 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43e6ae88 that was originally added here

01-22 12:02:28.701: ERROR/WindowManager(571): android.view.WindowLeaked: Activity com.digthisband.dtb.jg.View2 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43e6ae88 that was originally added here 01-22 12:02:28.701: ERROR/WindowManager(571): at android.view.ViewRoot.(ViewRoot.java:247) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.view.Window$LocalWindowManager.addView(Window.java:424) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.app.Dialog.show(Dialog.java:241) 01-22 12:02:28.701: ERROR/WindowManager(571): at com.digthisband.dtb.jg.View2$GetRSS.onPreExecute(View2.java:97) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.os.AsyncTask.execute(AsyncTask.java:391) 01-22 12:02:28.701: ERROR/WindowManager(571): at com.digthisband.dtb.jg.View2.getRSS(View2.java:87) 01-22 12:02:28.701: ERROR/WindowManager(571): at com.digthisband.dtb.jg.View2.onCreate(View2.java:68) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.os.Handler.dispatchMessage(Handler.java:99) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.os.Looper.loop(Looper.java:123) 01-22 12:02:28.701: ERROR/WindowManager(571): at android.app.ActivityThread.main(ActivityThread.java:4627) 01-22 12:02:28.701: ERROR/WindowManager(571): at java.lang.reflect.Method.invokeNative(Native Method) 01-22 12:02:28.701: ERROR/WindowManager(571): at java.lang.reflect.Method.invoke(Method.java:521) 01-22 12:02:28.701: ERROR/WindowManager(571): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-22 12:02:28.701: ERROR/WindowManager(571): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-22 12:02:28.701: ERROR/WindowManager(571): at dalvik.system.NativeStart.main(Native Method)

1

1 Answers

0
votes

It would be best if you could show the error LogCat, it will say what caused the Exception. I also noticed you were calling notifyDataSetChanged() in the doInBackground method- you should call this only in the UI thread.