sometime I have a strange problem with my xml views and contained sub elements in Android Eclipse SDK.
For example, I have a xml view called main.xml with a LinearLayout and a TextView as only child, with the id textView1. Everything works fine for a (long) time. When doing some major code changes, it might happen, that findViewById(R.id.textView1);
starts returning null. Recompilation does not change anything. That is strange.
After some time I found a workaround... I copied main.xml to main2.xml and changed setContentView(R.layout.main)
to setContentView(R.layout.main2)
and everything was working fine againg, without changing anything other than the layout reference, even the layout itself was only copied. No content was modified. After the first working run, I can delete main2.xml and set the layout back to R.layout.main
. No mo开发者_开发知识库re NullPointerException.
Does someone have an idea what is going wrong and how to fix this without doing the stupid copy thing?
Best, Hacksteak
It happens to me allot if there are problems with Eclipse, like a force close. What it works for me is cleaning the project until it get all resources and references right back.
精彩评论