Bizarre id mixup in XML layout



I have a strange situation in which the android build seems to be reading the id of one element as belonging to another one.


Here is the relevant XML:



<TextView
android:layout_marginTop="30dp"
android:id="@+id/tour_explanation"
android:layout_height="wrap_content"
android:layout_width="match_parent"
style="@android:style/TextAppearance.DeviceDefault.Large"/>
<LinearLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:id="@+id/audio_container"
android:orientation="horizontal">
</LinearLayout>


This is the line in the code that produces the error:



((TextView)v.findViewById(R.id.tour_explanation)).setText(b.getString(ToursPagerAdapter.STATION_TEXT));


And this is the error:



java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView


For some reason, the id from the TextView is being associated with the LinearLayout. I tried the LinearLayout with and without a closing tag -- no difference. If I reverse the order and put the TextView after the LinearLayout, the error goes away.


What causes this? How can I make it go away?


No comments:

Post a Comment