代码之家  ›  专栏  ›  技术社区  ›  xpepermint

Android TabHost内部LinearLayout

  •  0
  • xpepermint  · 技术社区  · 14 年前

    嘿。。。我试图创建一个布局结构如下的活动:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    
        <TabHost 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:layout_width="fill_parent"
                    android:layout_height="wrap_content" 
                    android:id="@android:id/tabs" 
                    /> 
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    >
                </FrameLayout>
            </LinearLayout>
         </TabHost>
    
         <some code here>
    
    </LinearLayout>
    

    这里怎么了?我的活动中出现了nullPointerException

    public class TabsActivity extends Activity
    {
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.tabs);
    
            // Resources res = getResources();
            // TabHost tabHost = (TabHost)findViewById(R.id.tabHost);
       }
    }
    

    问题在于嵌套。TabHost作为主XML节点没有问题。 谢谢!

    错误: Screenshot

    2 回复  |  直到 14 年前
        1
  •  0
  •   CommonsWare    14 年前

    你误解了你的堆栈跟踪。

    异常发生在内部 Intent . 这个 意图 您用于启动活动的无效。修好你的 意图 ,你的问题就会解决。

        2
  •  0
  •   noah    14 年前

    我有一个类似的问题,解决方法是 TabHost 打电话来 setup() . 很难说这是不是你的问题。