More eclipse insanity. Changing layout file turns TextViews into LinearLayouts

点点圈 提交于 2020-01-07 04:22:09

问题


Just made a change to my layout.xml Everything compiles and then I got a weird error back saying can't cast a TextView to ImageView. Another change and I got a weird error saying cannot cast THE SAME TextView to a LinearLayout??? It turns out although everything may compile fine, sometimes if you don't do a clean project your TextView widget might just be pointing to a RelativeLayout!!! Does anyone know why?


回答1:


So here's why:

You might have seen the file R.java in the gen folder.

Open that file up.

It contains memory addresses and identifiers for all the (R)esources.

When you change your layout files, these memory addresses become outdated and point to the wrong view element. A clean/build will delete the R.java file and recreate it, and is a necessary step after changing views.



来源:https://stackoverflow.com/questions/12310588/more-eclipse-insanity-changing-layout-file-turns-textviews-into-linearlayouts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!