2017-02-28 130 views
0

我試圖嵌入選項卡的和所有看起來很好,直到運行時被引發。我似乎無法看到最新儘管它的問題可能出在XML - 你TabHost必須具有的FrameLayout其id屬性爲「android.R.id.tabcontent」選項卡與在選項卡運行時錯誤

com.example.dawnlp.mymap, PID: 23323 
                        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dawnlp.mymap/com.example.dawnlp.mymap.Tab2Activity}: java.lang.RuntimeException: Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent' 
                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253) 
                         at android.app.ActivityThread.startActivityNow(ActivityThread.java:2977) 
                         at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:136) 
                         at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:348) 
                         at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:764) 
                         at android.widget.TabHost.setCurrentTab(TabHost.java:423) 
                         at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:193) 
                         at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:645) 
                         at android.view.View.performClick(View.java:5697) 
                         at android.view.View$PerformClick.run(View.java:22526) 
                         at android.os.Handler.handleCallback(Handler.java:739) 
                         at android.os.Handler.dispatchMessage(Handler.java:95) 
                         at android.os.Looper.loop(Looper.java:158) 
                         at android.app.ActivityThread.main(ActivityThread.java:7224) 
                         at java.lang.reflect.Method.invoke(Native Method) 
                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                        Caused by: java.lang.RuntimeException: Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent' 
                         at android.widget.TabHost.setup(TabHost.java:202) 
                         at android.widget.TabHost.setup(TabHost.java:222) 
                         at android.app.TabActivity.onContentChanged(TabActivity.java:135) 
                         at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:479) 
                         at android.app.Activity.setContentView(Activity.java:2387) 
                         at com.example.dawnlp.mymap.Tab2Activity.onCreate(Tab2Activity.java:28) 
                         at android.app.Activity.performCreate(Activity.java:6876) 
                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
                         at android.app.ActivityThread.startActivityNow(ActivityThread.java:2977)  
                         at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:136)  
                         at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:348)  
                         at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:764)  
                         at android.widget.TabHost.setCurrentTab(TabHost.java:423)  
                         at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:193)  
                         at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:645)  
                         at android.view.View.performClick(View.java:5697)  
                         at android.view.View$PerformClick.run(View.java:22526)  
                         at android.os.Handler.handleCallback(Handler.java:739)  
                         at android.os.Handler.dispatchMessage(Handler.java:95)  
                         at android.os.Looper.loop(Looper.java:158)  
                         at android.app.ActivityThread.main(ActivityThread.java:7224)  
                         at java.lang.reflect.Method.invoke(Native Method)  
                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)  
                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)  

我的代碼

public class Tab2Activity extends TabActivity 
{ 




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

     ///////////////////////// 

     TabHost tabHost2 = getTabHost(); 

     TabHost.TabSpec Gmapped = tabHost2.newTabSpec("InnerTabs"); 
     // setting Title and Icon for the Tab 
     Gmapped.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab3)); 
     Intent GmappedIntent = new Intent(this, Tab3Activity.class); 
     GmappedIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     Gmapped.setContent(GmappedIntent); 

     tabHost2.addTab(Gmapped); 

和tab.xml - 我認爲這個問題是在這裏

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:gravity="center" 
    android:background="#332b2b" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.dawnlp.mymap.Tab2Activity"> 

    <TabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
> 
    <LinearLayout 
     android:id="@+id/linearlayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 

     android:orientation="vertical" > 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

     </TabWidget> 

     <Button 
      android:id="@+id/veganfestival" 

      android:text="Aberdeen" 
      android:textColor="#FFFFFF" 
      android:textSize="30sp" 

      android:layout_width="match_parent" 
      android:layout_height="60dp" 
      android:background="@drawable/buttonshape" 
      android:shadowColor="#A8A8A8" 
      android:shadowDx="0" 
      android:shadowDy="0" 
      android:shadowRadius="5" 

      /> 
     <TextView 
      android:id="@+id/blank" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 

      android:textSize="20dp" 
      android:textColor="#ffffff" /> 
     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="#6f844a" /> 
     <TextView 
      android:id="@+id/venue" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Venue" 
      android:textSize="20dp" 
      android:textColor="#ffffff" /> 

     <TextView 
      android:id="@+id/address" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Address" 
      android:textSize="20dp" 
      android:textColor="#ffffff" /> 
     <TextView 
      android:id="@+id/city" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="City" 
      android:textSize="20dp" 
      android:textColor="#ffffff" /> 
     <TextView 
      android:id="@+id/postcode" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Postcode" 
      android:textSize="20dp" 
      android:textColor="#ffffff" /> 
     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="#6f844a" /> 
     <TextView 
      android:id="@+id/Vdate" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Date" 
      android:textSize="20dp" 
      android:textColor="#ffffff" /> 
     <TextView 
      android:id="@+id/Vtime" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Time" 
      android:textSize="20dp" 
      android:textColor="#ffffff" /> 
     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="#6f844a" /> 

     <TextView 
      android:id="@+id/blankagain" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 

      android:textSize="20dp" 
      android:textColor="#ffffff" /> 


     <Button 
      android:id="@+id/nav" 

      android:text="Take Me There" 
      android:textColor="#FFFFFF" 
      android:textSize="30sp" 

      android:layout_width="match_parent" 
      android:layout_height="60dp" 
      android:background="@drawable/buttonshape" 
      android:shadowColor="#A8A8A8" 
      android:shadowDx="0" 
      android:shadowDy="0" 
      android:shadowRadius="5" 

      /> 


    </LinearLayout> 
    </TabHost> 
    </ScrollView> 

回答

0

添加的FrameLayout在XML文件中。在framelayout內添加TabHost和其他子元素。

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:gravity="center" 
android:background="#332b2b" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.dawnlp.mymap.Tab2Activity"> 

<FrameLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 
<TabHost 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
> 
<LinearLayout 
    android:id="@+id/linearlayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:orientation="vertical" > 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

    </TabWidget> 

    <Button 
     android:id="@+id/veganfestival" 

     android:text="Aberdeen" 
     android:textColor="#FFFFFF" 
     android:textSize="30sp" 

     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:background="@drawable/buttonshape" 
     android:shadowColor="#A8A8A8" 
     android:shadowDx="0" 
     android:shadowDy="0" 
     android:shadowRadius="5" 

     /> 
    <TextView 
     android:id="@+id/blank" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:textSize="20dp" 
     android:textColor="#ffffff" /> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="#6f844a" /> 
    <TextView 
     android:id="@+id/venue" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Venue" 
     android:textSize="20dp" 
     android:textColor="#ffffff" /> 

    <TextView 
     android:id="@+id/address" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Address" 
     android:textSize="20dp" 
     android:textColor="#ffffff" /> 
    <TextView 
     android:id="@+id/city" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="City" 
     android:textSize="20dp" 
     android:textColor="#ffffff" /> 
    <TextView 
     android:id="@+id/postcode" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Postcode" 
     android:textSize="20dp" 
     android:textColor="#ffffff" /> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="#6f844a" /> 
    <TextView 
     android:id="@+id/Vdate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Date" 
     android:textSize="20dp" 
     android:textColor="#ffffff" /> 
    <TextView 
     android:id="@+id/Vtime" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Time" 
     android:textSize="20dp" 
     android:textColor="#ffffff" /> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="#6f844a" /> 

    <TextView 
     android:id="@+id/blankagain" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:textSize="20dp" 
     android:textColor="#ffffff" /> 


    <Button 
     android:id="@+id/nav" 

     android:text="Take Me There" 
     android:textColor="#FFFFFF" 
     android:textSize="30sp" 

     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:background="@drawable/buttonshape" 
     android:shadowColor="#A8A8A8" 
     android:shadowDx="0" 
     android:shadowDy="0" 
     android:shadowRadius="5" 

     /> 


</LinearLayout> 
</TabHost> 
</FrameLayout> 
</ScrollView> 
+0

謝謝你@sakikumar。但拋出的錯誤 你TabHost必須具有的FrameLayout其id屬性爲 'android.R.id.tabcontent' –

+0

的 TabHost機器人:ID = 「@機器人:ID/android.R.id.tabhost」 是否顯示錯誤 –

+0

android:id =「@ android:id/tabhost」 – sasikumar

相關問題