2013-12-21 68 views
2

此代碼用於正常工作,但在更新構建工具和sdk後,我開始獲取此轉換異常。誰知道怎麼修它?android.support.v4.app.FragmentTabHost無法轉換爲android.widget.LinearLayout

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main_tab_view); 

    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); 

    TabWidget tw = (TabWidget) findViewById(android.R.id.tabs); 
    LinearLayout ll = (LinearLayout) tw.getParent(); //error happens on this line 
    ... 
    } 

main_tab_view.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <FrameLayout 
      android:id="@+id/realtabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" /> 

     <android.support.v4.app.FragmentTabHost 
      android:id="@android:id/tabhost" 
      android:layout_width="match_parent" 

      android:layout_height="wrap_content" > 

      <TabWidget 
       android:id="@android:id/tabs" 

       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" /> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="0dp" 
       android:layout_height="0dp" 
       android:layout_weight="0" /> 
     </android.support.v4.app.FragmentTabHost> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/left_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@color/blue_actionbar_light" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="10dp" 
     android:listSelector="@drawable/selectable_background_darkblue" /> 

</android.support.v4.widget.DrawerLayout> 

了java.lang.RuntimeException:無法啓動活動 java.lang.ClassCastException:android.support.v4.app.FragmentTabHost 不能投到android.widget.LinearLayout

回答

1

我終於設法修復它。我不得不恢復到過去支持庫的版本。幸運的是我有一個備份。我也使用了相同的android sdk來構建它曾經工作過的。

相關問題