我有我的onCreate()
这种看似无辜findViewById()
其不断返回null:什么时候findViewById()返回null?
mCheckLicenseButton = (Button) findViewById(R.id.btn_checkout);
我res/layout/main.xml
clearnly包含此按钮:
<Button android:id="@+id/btn_checkout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/top_textview"
android:layout_alignParentRight="true"
android:text="Check License" />
所以我不明白为什么findViewById()
返回null。
findViewById()
在什么情况下返回null?
很明显,findViewById()
没有成功找到布局资源,但有什么可以解释这一点?
我假设main.xml是加载的布局?你是否也定义了多个布局(例如,纵向/横向),如果两个都定义了布局? – jkhouw1 2011-06-15 17:41:33