2012-06-11 54 views
0

我有一個應用程序,它使用aSync任務來挖掘一些HTML數據,它工作正常,直到我嘗試在我的應用程序上使用TabHost。事情是,當我嘗試打開這個選項卡時,它彈出ProgressDialog,但一會兒它進入doInBackground方法內部的catch,並且Exception是null,而不是NullPoint,只是e=null,並且沒有將適配器設置爲來自採礦的數據。下面是一些代碼:問題與TabHost和異步任務

onCreate(){ 
    ... 
    this.pd = ProgressDialog.show(this, "Downloading..", 
      "Downloading...", true, false); 
    this.pd.setCanceledOnTouchOutside(false); 
    this.pd.setCancelable(true); 
    ... 
    task = new DownloadTask().execute("Starting"); 
} 

而且

private class DownloadTask extends AsyncTask<String, Void, Object> { 

    protected Object doInBackground(String... args) { 
     search = new Search(person); 
     try { 
      search.Login(); 
      data = search.ParseData(); 

     } catch (Exception e) { 
      erroUnknown = true; 
     } 
     adapter = new RowAdapter(DataActivity.this, data); 
    } 
} 

而且tabActivity:

public class TabMenu extends TabActivity { 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.menu); 

    Resources res = getResources(); // Resource object to get Drawables 
    TabHost tabHost = getTabHost(); // The activity TabHost 
    TabHost.TabSpec spec; // Resusable TabSpec for each tab 
    Intent intent; // Reusable Intent for each tab 

    // Create an Intent to launch an Activity for the tab (to be reused) 
    intent = new Intent().setClass(this, DataActivity.class); 

    // Initialize a TabSpec for each tab and add it to the TabHost 
    spec = tabHost 
      .newTabSpec("data") 
      .setIndicator("Data", 
        res.getDrawable(R.drawable.ic_launcher)) 
      .setContent(intent); 
    tabHost.addTab(spec); 
    //Just test 
      spec = tabHost 
      .newTabSpec("artists") 
      .setIndicator("Artists", 
        res.getDrawable(R.drawable.ic_launcher)) 
      .setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(0); 
} 

} 

任何想法,爲什麼它進入catch塊?使用tabActivity時是否需要修改一些代碼?

在此先感謝

更新: 雖然有時調試,我得到了E = IllegalStateException異常從entity.getContent(),即使是第一次被調用。和StringOutOfBoundsException,因爲內容沒有獲取正確的數據,我的意思是,沒有它登錄的標籤,並且工作頁面,但是對於tabHost它沒有,它是如何受到tabHost影響的?

回答

0

明白了,是一個意圖通過另一個活動,必須傳遞給TabActivity ..