我目前正在开发一个Android的应用程序,这需要使用一个定制的标签。我遇到了两个问题:
我将从我的第一个问题开始:
java.lang.NullPointerException
at android.widget.TabWidget.initTabWidget(TabWidget.java:115)
at android.widget.TabWidget.<init>(TabWidget.java:86)
at android.widget.TabWidget.<init>(TabWidget.java:69)
...当我想在Eclipse中从文本模式切换到wyswig模式时,我得到了这个异常。这是给我这个错误的实际xml代码:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android: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">
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:padding="20dip"
android:background="#fff" />
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:checkedButton="@+id/first"
android:id="@+id/states">
<RadioButton android:id="@+id/first"
android:background="#FF00FF"
android:width="80dip"
android:height="70dip" />
<RadioButton android:id="@+id/second"
android:background="#FFFFFF"
android:width="80dip"
android:height="70dip" />
<RadioButton android:id="@+id/third"
android:background="#00FFFF"
android:width="80dip"
android:height="70dip" />
<RadioButton android:id="@+id/fourth"
android:background="#0000FF"
android:width="80dip"
android:height="70dip" />
</RadioGroup>
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:visibility="gone" />
</LinearLayout>
</TabHost>现在第二个问题是一个图形工件:

我如何解决我的问题?
发布于 2010-11-20 06:52:01
我已经设法修复了我认为是视觉制品的东西:
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:background="#FFFFFF" />而且似乎每当我在我的项目中使用TabHost和TabWidget时,我都会遇到这个异常,我也在android tutorials上检查过:http://developer.android.com/resources/tutorials/views/hello-tabwidget.html,是的,我也得到了它
发布于 2010-11-20 06:30:19
错误之处非常明显,而且Eclipse中的消息会非常准确地告诉您错误是什么。您的FrameLayout没有内容。
您试图使用该FrameLayout实现什么目的
更新:刚刚意识到你想要做什么。试试这个布局。
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android: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">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:padding="20dip"
android:background="#fff">
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:checkedButton="@+id/first"
android:id="@+id/states">
<RadioButton
android:id="@id/first"
android:background="#FF00FF"
android:width="80dip"
android:height="70dip"/>
<RadioButton
android:id="@+id/second"
android:background="#FFFFFF"
android:width="80dip"
android:height="70dip"/>
<RadioButton
android:id="@+id/third"
android:background="#00FFFF"
android:width="80dip"
android:height="70dip"/>
<RadioButton
android:id="@+id/fourth"
android:background="#0000FF"
android:width="80dip"
android:height="70dip"/>
</RadioGroup>
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:visibility="gone"/>
</LinearLayout>
</TabHost>我还为您纠正了另一个错误。实际上不一定是一个错误,但仍然是这样。在RadioGroup中,当您引用第一个RadioButton时,您为它分配了ID first和android:checkedButton="@+id/first"。当您实际到达RadioButton时,您的ID定义不应该再包含+。检查布局。
https://stackoverflow.com/questions/4229894
复制相似问题