在用Eclipse进行Android的界面开发,通过findViewById试图获取界面元素对象时,该方法有时候返回null,造成这种情况主要有以下两种情形。
第一种情形是最普通的。
比如main.xml如下,其中有一个ListView,其id为lv_contactbook
<?xml version=1.0encoding=utf-8?>
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
android:orientation=vertical
android:layout_widt