我尝试使用嵌入式标签,并且在投入运行时之前一切正常。我似乎无法看到问题,尽管它可能在于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 :(得分:0)
在xml文件中添加framelayout。在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>