Android XML布局中奇怪的id混淆
我遇到了一个奇怪的情况,android构建似乎在读取一个元素的id作为属于另一个元素 以下是相关的XML:Android XML布局中奇怪的id混淆,android,xml,android-layout,Android,Xml,Android Layout,我遇到了一个奇怪的情况,android构建似乎在读取一个元素的id作为属于另一个元素 以下是相关的XML: <TextView android:layout_marginTop="30dp" android:id="@+id/tour_explanation" android:layout_height="wrap_content" android:layout_width="match_parent"
<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>
这就是错误:
((TextView)v.findViewById(R.id.tour_explanation)).setText(b.getString(ToursPagerAdapter.STATION_TEXT));
java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
出于某种原因,文本视图中的id
与LinearLayout关联。我尝试了线性布局,有结束标记和没有结束标记——没有区别。如果我颠倒顺序,将TextView放在LinearLayout之后,错误就会消失
这是什么原因?如何让它消失?清理您的项目(例如,project>Clean in Eclipse)。太棒了!非常感谢!