不幸的是,lastRide已经停止(Android)

不幸的是,lastRide已经停止(Android),android,Android,我在emulator上不断遇到此错误: 我从一个教程中复制了这个,但仍然不起作用。当我运行我的应用程序时,它显示-不幸的是,lastRide已经停止。有什么想法吗 不过,控制台中没有给出任何错误 main.xml <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://s

我在emulator上不断遇到此错误:

我从一个教程中复制了这个,但仍然不起作用。当我运行我的应用程序时,它显示-不幸的是,lastRide已经停止。有什么想法吗

不过,控制台中没有给出任何错误

main.xml

  <?xml version="1.0" encoding="utf-8"?>
  <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@android:id/tabhost"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  tools:ignore="HardcodedText" >

   <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

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

    <LinearLayout
        android:id="@+id/fr"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <CheckBox android:text="rawted" />

        <CheckBox android:text="rawted" />

        <CheckBox android:text="rawted" />

         <CheckBox android:text="rawted" />
          </LinearLayout>

         </LinearLayout>

       </TabHost>

您需要移动
setContentView
,以便在调用tabhost之前执行此操作


当您使用
getTabHost
时,框架正在尝试在活动视图中查找小部件,但无法找到,因为尚未设置视图。

Change

TabHost mTabHost = getTabHost(); // declare as TabHost in your code
setContentView(R.layout.main);

setContentView(R.layout.main);
TabHost mTabHost = getTabHost(); // declare as TabHost in your code
请记住,当您试图通过控件ID引用任何控件(按钮、TextView、TabHost)时。
您必须始终在调用setContentView后执行此操作。

您可以发送您提到的教程链接吗?谢谢先生。还可以告诉我如何向每个选项卡添加更多内容吗?在您展示的实现中,您可以添加到视图继承人权限,只需将
setContent
指向最顶层即可。您将用新布局替换发布的XML中的
textview1
元素,然后将
setContent
指向新布局的最顶层。我想我误解了内容的含义。我的意思是,我想在每个选项卡中添加多个复选框。但不是垂直的,就像在“彼此”复选框下一样。同样,通过添加包装在LinearLayout或RelativeLayout中的复选框来修改发布的xml布局,以取代其中一个文本视图,并将
setContent
指向LinearLayout(或RelativeLayout),从而生成另一个xml文件?还是用同一个?它是否像setContentView(R.id.LinearLayout)?谢谢你,先生。还可以告诉我如何为每个选项卡添加更多内容吗?
setContentView(R.layout.main);
TabHost mTabHost = getTabHost(); // declare as TabHost in your code