Android 找不到文本视图
这简直让我发疯,我不知道到底发生了什么。 我有一个xml布局,在一个可点击的RelativeLayout中有一个TextViewAndroid 找不到文本视图,android,textview,Android,Textview,这简直让我发疯,我不知道到底发生了什么。 我有一个xml布局,在一个可点击的RelativeLayout中有一个TextView <RelativeLayout android:id="@+id/bg_section" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_m
<RelativeLayout
android:id="@+id/bg_section"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@color/almost_black"
android:clickable="true"
android:onClick="goToBG"
android:padding="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Go To B.G."
android:textColor="@color/white"
android:textSize="20sp" />
<ImageView
android:id="@+id/bg_arrow"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="-10dp"
android:src="@drawable/arrow_icon" />
<TextView
android:id="@+id/current_bg_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/bg_arrow"
android:text="3"
android:textColor="@color/holo_blue"
android:textSize="22sp" />
</RelativeLayout>
这在我设置文本的行上给出了ResourceNotFountException,尽管找到RelativeLayout没有问题。即使我试图通过id找到它,如下所示:
TextView bgCountTV = (TextView) findViewById(R.id.current_bg_count)
bgCountTV.setText(tempBG.size());
它给出了同样的错误。
布局中的所有其他视图都很容易找到,并且更新得很好。只有这一个文本视图给了我问题。有人知道问题出在哪里吗?您需要将ArrayList的大小转换为此行的字符串
setText(tempBG.size())
由于tempBG.size返回一个int,因此setText正在寻找一个id为返回值的资源。如果您有要用于设置文本的字符串资源,则使用
所以把它改成
setText(String.valueOf(tempBG.size()));
您需要在此行将ArrayList的大小转换为字符串
setText(tempBG.size())
由于tempBG.size返回一个int,因此setText正在寻找一个id为返回值的资源。如果您有要用于设置文本的字符串资源,则使用
所以把它改成
setText(String.valueOf(tempBG.size()));
尝试将tempBG.size设置为如下字符串
bgCountTV.setText(""+tempBG.size());
这应该行得通尝试将tempBG.size设置为如下字符串
bgCountTV.setText(""+tempBG.size());
这应该行得通您在使用eclipse吗?检查项目中是否没有错误和警告。有时xml中会出现一些错误,可以让您编译,但无法正常工作。您使用的是eclipse吗?检查项目中是否没有错误和警告。有时,xml中存在允许您编译的错误,但无法正常工作。问题在于此代码
bgCountTV.setText(tempBG.size());
tempBG.size此代码返回一个int值,它假定为字符串资源id,类似于R.string.VARIABLE_NAME,因为它有一个对应的int值,TextView假定为id
你能做什么
bgCountTV.setText(tempBG.size()+"");
或
或
问题在于这个代码
bgCountTV.setText(tempBG.size());
tempBG.size此代码返回一个int值,它假定为字符串资源id,类似于R.string.VARIABLE_NAME,因为它有一个对应的int值,TextView假定为id
你能做什么
bgCountTV.setText(tempBG.size()+"");
或
或
你试过清理你的项目吗?Project->Clean…尝试清理您的项目。tempBG指的是什么?那是一个数组吗?是的,这还没有修复它!确保将codeMagic的答案标记为正确。您是否尝试过清理您的项目?Project->Clean…尝试清理您的项目。tempBG指的是什么?那是一个数组吗?是的,这还没有修复它!一定要把codeMagic的答案标记为正确的。它真的很简单。真不敢相信。谢谢setText必须是一个问题,因为这是使用getChild和findViewById尝试之间唯一的共同点,两者都不起作用;接受它作为答案,如果它解决了你的问题。仅仅说声谢谢是不够的。这真的很简单。真不敢相信。谢谢setText必须是一个问题,因为这是使用getChild和findViewById尝试之间唯一的共同点,两者都不起作用;接受它作为答案,如果它解决了你的问题。说谢谢是不够的。