问题
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