2012-01-09 20 views
1

私のアプリでお気に入りタブを選択したときに「お気に入り」リストビューを読み込もうとしています。すべてのタブが正しく表示されますが、お気に入りを選択するとIllegalStateException例外が発生するためアプリがクラッシュします。次のようにタブが選択されたときにアクティビティを読み込む

Javaコードは次のとおりです。

public class tabs extends Activity{ 


     protected void onCreate(Bundle savedInstanceState) { 

      super.onCreate(savedInstanceState); 
      setContentView(R.layout.tabmain); 

      TabHost tabs=(TabHost)findViewById(R.id.tabhost); 

      tabs.setup(); 

      TabHost.TabSpec spec=tabs.newTabSpec("tag1");  
      spec.setContent(R.id.tab1); 
      spec.setIndicator("tab1"); 
      tabs.addTab(spec); 

      spec=tabs.newTabSpec("tag2"); 
      spec.setContent(R.id.tab2); 
      spec.setIndicator("tab2"); 
      tabs.addTab(spec); 

      spec=tabs.newTabSpec("tag3"); 
      spec.setIndicator("Favourites", getResources().getDrawable(R.drawable.favourites_star)); 
      spec.setContent(new Intent(this,favourites.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); 
      tabs.addTab(spec); 


     } 


    } 


    The xml file is as follows: 

    <?xml version="1.0" encoding="utf-8"?> 
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+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"> 
     <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"> 

      <LinearLayout 
      android:id="@+id/tab1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical"/> 

      <LinearLayout 
      android:id="@+id/tab2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical"/> 

      <LinearLayout 
      android:id="@+id/tab3" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical"/> 

     </FrameLayout> 
     </LinearLayout> 
    </TabHost> 


Stack Trace: 

Thread [<3> main] (Suspended (exception IllegalStateException)) 
    ViewRoot.handleMessage(Message) line: 1740 
    ViewRoot(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 123 
    ActivityThread.main(String[]) line: 4363  
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] 
    Method.invoke(Object, Object...) line: 521 
    ZygoteInit$MethodAndArgsCaller.run() line: 860 
    ZygoteInit.main(String[]) line: 618 
    NativeStart.main(String[]) line: not available [native method] 
+1

ここにあなたのlogcatを投稿してください。 –

答えて

0

あなたfavourites活動が定義されていることを確認してくださいAndroidのマニフェスト・ファイル内の

+0

お気に入りアクティビティはマニフェストで定義されています。 – user615099

関連する問題