2011-01-22 80 views
0

我試圖在抓取RSS feed時顯示不確定的ProgressDialog。我彈出對話框,但一旦結果返回,我就會關閉一個關卡。我懷疑是適配器被填充並去更新UI。代碼如下。我懷疑是否正確?Android Force Close ProgressDialog

 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; 
     } 
    } 
    */ 

這裏是堆棧轉儲 - 很明顯,通知的呼叫是問題。現在,我只是有麻煩搞清楚打電話通知:

01-22 12:02:28.701: ERROR/WindowManager(571): Activity com.digthisband.dtb.jg.View2 has leaked window [email protected] that was originally added here 

十二月1日至22日:02:28.701:ERROR /窗口管理器(571):android.view.WindowLeaked:活動com.digthisband.dtb。 jg.View2泄露了窗口[email protected],最初在這裏添加 01-22 12:02:28.701:錯誤/ WindowManager(571):在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):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 01-22 12:02:28.701:錯誤/ WindowManager(571):在android.view.Window $ LocalWindowManager.addView(Window.java:424) 01-22 12:02:28.701:錯誤/ WindowManager(571):在android.app.Dialog.show(Dialog.java:241) 01-22 12:02:28.701:錯誤/ WindowManager(571):at com.digthisband.dtb.jg.View2 $ GetRSS.onPreExecute(View2.java:97) 01-22 12:02:28.701:錯誤/ 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 :錯誤/ WindowManager(571):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-22 12:02:28.701:錯誤/ WindowManager(571):在android.app.ActivityThre ad.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:錯誤/ WindowManager(571):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125) 01-22 12:02:28.701:錯誤/ WindowManager(571):at android.app.ActivityThread $ H (Handle.java:99) 01-22 12:02:28.701 :錯誤/ WindowManager(571):在android.os.Looper.loop(Looper.java:123) 01-22 12:02:28.701:錯誤/ WindowManager(571):在android.app.ActivityThread.main(ActivityThread .java:4627) 01-22 12:02:28.701:ERROR/WindowManager(571):在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 :錯誤/ WindowManager(571):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868) 01-22 12:02:28.701:錯誤/ 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)

回答

0

它會如果你能顯示錯誤LogCat,那麼最好的辦法是說明是什麼導致了異常。 我也注意到你在doInBackground方法中調用了notifyDataSetChanged(),你應該只在UI線程中調用它。

+0

你是絕對正確的 - 我已經刪除了對notifyDataSetChanged的調用,並且崩潰消失了。我也沒有得到我的數據。但是這是一個開始... – voodoobilly 2011-01-22 16:49:11