I have this problem accessing TextView inside Relative Layout inside LinearLayout
Let’s say I have these views in the file row.xml
<LinearLayout>
<TextView android:id="@+id/title" />
<RelativeLayout android:id="@+id/a_parent">
<TextView android:id="@+id/a">
</RelativeLayout>
<RelativeLayout android:id="@+id/b_parent">
<TextView android:id="@+id/b">
</RelativeLayout>
</LinearLayout>
Now I want to change the value of TextViews from an activity
LayoutInflater li=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout temp=(LinearLayout) li.inflate(R.layout.row, null);
((TextView)temp.findViewById(R.id.title)).setText("This is title");
RelativeLayout rl=(RelativeLayout)temp.findViewById(R.id.a_parent);
((TextView)rl.findViewById(R.id.a)).setText("an this is the content of a");
I can successfully set the TextView of id ‘title’, but an error appears when approaching the last line. It says that the error was caused by android.content.res.Resources$NotFoundException: String resource ID #0x1
Can anyone tell me what is wrong, how to fix it, and why does the code not work as I expected?
Thanks
Your Exception is a ResourcesNotFoundException for a String. Are you setting the value of the TextView using
getString? And if so, are you sure that this string exists in your strings.xml file? If not, did you maybe reference one of your views withR.string.nameinstead ofR.id.name? It looks like you modified your code for posting, it may be easier to help if you posted exactly what you’re doing in the original, as well as the full stack trace.Sometimes problems with Resources occur because the R file isn’t up to date with new code. I would also try Rebuilding/Cleaning your project and see if that helps.