Android-findViewById不工作

Android-findViewById不工作,android,listview,Android,Listview,我完全不知所措 我在一个不是主要活动的活动中有代码 详情如下: @Override protected void onCreate(Bundle savedInstanceState) { while (bsp <10) { list.add(bsp.toString()); bsp++; } super.onCreate(savedInstanceState); setContentView(R.layout.fra

我完全不知所措

我在一个不是主要活动的活动中有代码

详情如下:

@Override
protected void onCreate(Bundle savedInstanceState) {
    while (bsp <10)
    {
        list.add(bsp.toString());
        bsp++;
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_view);
    ListView view;
    view = (ListView)findViewById(R.id.view);
有人有主意吗

正如所质疑的,这里是片段:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.example.myapp.ViewActivity$PlaceholderFragment" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />
<ListView
    android:id=”@+id/view″
    android:layout_width=”fill_parent”
    android:layout_height=”wrap_content” >
</ListView>


</RelativeLayout>


或者有其他方法获取视图吗?

您的任何布局都没有id为
view
的视图,因此
R.id.view
不会解析为生成的
R
中的字段

确保您试图查找的id是您在XML中引入的id,例如,
@+id/

要使
findViewById()
返回非空结果,请确保在作为内容视图的布局中找到id,在本例中为
layout/fragment_view.xml



在您发布的布局中,您似乎拥有
@+id/view
。如果生成的
R
是旧的、过时的版本,请清理并重新生成项目。

没有一个布局具有id
view
的视图,因此
R.id.view
不会解析为生成的
R
中的字段

确保您试图查找的id是您在XML中引入的id,例如,
@+id/

要使
findViewById()
返回非空结果,请确保在作为内容视图的布局中找到id,在本例中为
layout/fragment_view.xml



在您发布的布局中,您似乎拥有
@+id/view
。如果生成的
R
是旧的、过时的版本,请清理并重新生成项目。

没有一个布局具有id
view
的视图,因此
R.id.view
不会解析为生成的
R
中的字段

确保您试图查找的id是您在XML中引入的id,例如,
@+id/

要使
findViewById()
返回非空结果,请确保在作为内容视图的布局中找到id,在本例中为
layout/fragment_view.xml



在您发布的布局中,您似乎拥有
@+id/view
。如果生成的
R
是旧的、过时的版本,请清理并重新生成项目。

没有一个布局具有id
view
的视图,因此
R.id.view
不会解析为生成的
R
中的字段

确保您试图查找的id是您在XML中引入的id,例如,
@+id/

要使
findViewById()
返回非空结果,请确保在作为内容视图的布局中找到id,在本例中为
layout/fragment_view.xml



在您发布的布局中,您似乎拥有
@+id/view
。如果生成的
R
是旧版本,请清理并重新生成项目。

您的引号很奇怪,与其他引号不同,请尝试替换:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />
<ListView
    android:id=”@+id/view″
    android:layout_width=”fill_parent”
    android:layout_height=”wrap_content” >
</ListView>


您的引号很奇怪,与其他引号不同。请尝试替换:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />
<ListView
    android:id=”@+id/view″
    android:layout_width=”fill_parent”
    android:layout_height=”wrap_content” >
</ListView>


您的引号很奇怪,与其他引号不同。请尝试替换:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />
<ListView
    android:id=”@+id/view″
    android:layout_width=”fill_parent”
    android:layout_height=”wrap_content” >
</ListView>


您的引号很奇怪,与其他引号不同。请尝试替换:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />
<ListView
    android:id=”@+id/view″
    android:layout_width=”fill_parent”
    android:layout_height=”wrap_content” >
</ListView>




请发布您的XML设计为什么要用一个名为
片段视图
的XML布局文件设置
活动
的内容视图?还有,为什么你要强调你的
活动
不是主要活动?因为在我读到的其他一些帖子中,用户似乎认为这很重要。而且,我处理的大多数教程仅在主要活动中使用。但是,当我将xml代码放入activity_视图而不是fragment_视图时,我遇到了相同的问题?@为什么您的listview的引号与其他视图不同?我发布了它,谢谢您!!请发布您的XML设计为什么要使用名为
fragment\u view
的XML布局文件设置
活动的内容视图?还有,为什么你要强调你的
活动
不是主要活动?因为在我读到的其他一些帖子中,用户似乎认为这很重要。而且,我处理的大多数教程仅在主要活动中使用。但是,当我将xml代码放入activity_视图而不是fragment_视图时,我遇到了相同的问题?@为什么您的listview的引号与其他视图不同?我发布了它,谢谢您!!请发布您的XML设计为什么要使用名为
fragment\u view
的XML布局文件设置
活动的内容视图?还有,为什么你要强调你的
活动
不是主要活动?因为在我读到的其他一些帖子中,用户似乎认为这很重要。而且,我处理的大多数教程仅在主要活动中使用。但是,当我将xml代码放入activity_视图而不是fragment_视图时,我遇到了相同的问题?@为什么您的listview的引号与其他视图不同?我发布了它,谢谢您!!请发布您的XML设计为什么要使用名为
fragment\u view
的XML布局文件设置
活动的内容视图?还有,为什么你要强调你的
活动
不是主要活动?因为在我读到的其他一些帖子中,用户似乎认为这很重要。而且,我处理的大多数教程仅在主要活动中使用。但是,当我将xml代码放入activity_视图而不是fragment_视图时,我遇到了相同的问题?@为什么您的listview的引号与其他视图不同?我发布了它,谢谢您!!是的,尝试清理和重建。好吧,在那之后,课程基本上都读过了,提示我应该导入android.R,这并没有改变什么,因为突然出现了很多错误。其次,XML中的ListView现在似乎是