首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >eclipse for android和visual-artifacts中wyswig xml布局中的nullpointerexception

eclipse for android和visual-artifacts中wyswig xml布局中的nullpointerexception
EN

Stack Overflow用户
提问于 2010-11-20 06:19:29
回答 2查看 585关注 0票数 1

我目前正在开发一个Android的应用程序,这需要使用一个定制的标签。我遇到了两个问题:

我将从我的第一个问题开始:

代码语言:javascript
复制
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代码:

代码语言:javascript
复制
<?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>

现在第二个问题是一个图形工件:

我如何解决我的问题?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-11-20 06:52:01

我已经设法修复了我认为是视觉制品的东西:

代码语言:javascript
复制
<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,是的,我也得到了它

票数 0
EN

Stack Overflow用户

发布于 2010-11-20 06:30:19

错误之处非常明显,而且Eclipse中的消息会非常准确地告诉您错误是什么。您的FrameLayout没有内容。

您试图使用该FrameLayout实现什么目的

更新:刚刚意识到你想要做什么。试试这个布局。

代码语言:javascript
复制
<?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 firstandroid:checkedButton="@+id/first"。当您实际到达RadioButton时,您的ID定义不应该再包含+。检查布局。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4229894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档