2012-02-25 6 views
0

はAsyncTaskでアンドロイドのビュービューを見つけることができません

xmlファイルと私のAsyncTaskに問題があります。

private class GetDataTask extends AsyncTask<Void, Void, Integer> { 
    Context  context; 

    GetDataTask(Context context){this.context=context;} 
    protected Integer doInBackground(Void... params) { 

      int waited = 0; 
      while (waited < 5000) { 
      try { 
      this.wait(100); 
     } catch (InterruptedException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
      waited += 100; 
      } 
      return 1; 
    } 

    protected void onPostExecute(Integer result) { 
     tabs.this.setContentView(R.layout.tabs); 
     //setContentView(R.layout.tabs); 

     TabHost tabHost= (TabHost)tabs.this.findViewById(android.R.id.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(context,start.class); 

     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabHost.newTabSpec("Heb news").setIndicator("Heb news").setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same for the other tabs 
     intent = new Intent().setClass(context, rusNewsP.ListRusNews.class); 

     spec = tabHost.newTabSpec("Rus News").setIndicator("Rus News").setContent(intent); 
     tabHost.addTab(spec); 
     tabHost.setCurrentTab(0); 
    } 
} 

そして、私のXMLは次のとおりです:

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp"> 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp" /> 
</LinearLayout> 
私の問題は、私はエラーが私のコードがある

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.News/startPakage.tabs}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 

ある に私のコードに若干の誤差が出ることができないということです

どのようにすれば動作するコードを修正できますか?このコードは、アプリケーションが起動する前にロゴを表示するためのものです。

答えて

1

thisonPostExecuteは、タイプAsyncTaskのオブジェクトを意味します。 AsyncTaskをインプレースに作成する場合は、

class MyActivity : extends Activity { 
    // ... 

    void foo() { 
    my asyncTask = new AsyncTask<Void, Void, Int >() { 
     // ... 

     protected void onPostExecute(Integer result) { 
     MyActivity.this.setContentView(R.layout.tabs); 
     tabs = (TabHost) MyActivity.this.findViewById(android.R.id.tabhost); 
     } 
    }; 
    asyncTask.execute(); 
    } 
}; 
+1

私は自分の投稿の更新情報を参照してください –

関連する問題