Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法将android.widget.TextView强制转换为android.view.ViewGroup0_Android_Android Layout_Android Studio_Android Widget_Textview - Fatal编程技术网

无法将android.widget.TextView强制转换为android.view.ViewGroup0

无法将android.widget.TextView强制转换为android.view.ViewGroup0,android,android-layout,android-studio,android-widget,textview,Android,Android Layout,Android Studio,Android Widget,Textview,找不到此错误的来源。 看到了关于同一问题的其他问题,这通常是由缺少结束标记引起的。但是找不到我的代码中缺少哪一个 <TextView android:text="@string/hello_world" android:layout_width="match_parent" android:layout_height="match_parent" > </TextView> </LinearLayout> My main activ

找不到此错误的来源。 看到了关于同一问题的其他问题,这通常是由缺少结束标记引起的。但是找不到我的代码中缺少哪一个

<TextView
    android:text="@string/hello_world"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</TextView>

</LinearLayout>
My main activity.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="horizontal">

<TextView
    android:text="@string/main_textview"
    android:layout_width="0px"
    android:layout_weight="2"
    android:background="#FFF8DC"
    android:padding="@dimen/component_padding"
    android:layout_height="match_parent" >
</TextView>

<TextView
    android:id="@+id/simplefragment"
    android:layout_width="0px"
    android:layout_weight="2"
    android:orientation="vertical"
    android:padding="@dimen/component_padding"
    android:layout_height="match_parent" >
</TextView>

</LinearLayout>
<TextView
    android:text="@string/hello_world"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</TextView>

</LinearLayout>

Viewgroup
表示可以包含其他视图的视图。你分别打开和关闭你的文本视图,当它们不能打开和关闭时,将它们变成一个组

<TextView
    android:text="@string/hello_world"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</TextView>

</LinearLayout>
根据您发布的代码,解决方案是删除所有
,并使用
/>
直接在属性末尾将其关闭,例如:

<TextView
    android:text="@string/hello_world"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</TextView>

</LinearLayout>
<TextView
    android:id="@+id/simplefragment"
    android:layout_width="0px"
    android:layout_weight="2"
    android:orientation="vertical"
    android:padding="@dimen/component_padding"
    android:layout_height="match_parent" />


在所有文本视图中执行此操作。另外,检查是否有带有任何其他视图的
标记,如果有,则应将其删除并放置在其他位置。

我认为您可能已找到该特定文本视图并将其转换为视图组,例如:

<TextView
    android:text="@string/hello_world"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</TextView>

</LinearLayout>
视图组simpleFragment=(视图组) findViewById(R.id.simplefragment)

<TextView
    android:text="@string/hello_world"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</TextView>

</LinearLayout>
无法将textview强制转换为视图组,因为它不是视图组,textview是视图

<TextView
    android:text="@string/hello_world"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</TextView>

</LinearLayout>
如果您查看android文档,textview会扩展视图:

<TextView
    android:text="@string/hello_world"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</TextView>

</LinearLayout>

视图组是像RelativeLayout或LinearLayouts或FrameLayouts这样的对象,它们可以包含多个视图。

您是否试图将TextView用作片段的容器?检查@Blackbelt确实我想将其用作片段的容器,我做错了什么?不要使用TextView。使用框架布局。我应该编辑哪一个?
<TextView
    android:text="@string/hello_world"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</TextView>

</LinearLayout>