0

嘿...我正在尝试使用这样的布局结构创建一个活动:

<?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 节点没有问题。谢谢!

错误: 截屏

4

2 回答 2

0

我遇到了类似的问题,解决方案是获取TabHostand 调用setup(). 很难说这是否是你的问题。

于 2010-09-23T20:30:24.207 回答
0

您误解了堆栈跟踪。

异常发生在里面IntentIntent您用来启动活动的 无效。修复你的Intent,你的问题就会消失。

于 2010-09-19T12:09:44.967 回答