I have this seemingly innocent findViewById()
in my onCreate()
which keeps returning null:
mCheckLicenseButton = (Button) findViewById(R.id.btn_checkout);
My res/layout/main.xml
clearnly contains this button:
<Button android:id="@+id/btn_checkout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="w开发者_开发百科rap_content"
android:layout_below="@+id/top_textview"
android:layout_alignParentRight="true"
android:text="Check License" />
So I don't understand why findViewById()
returns null.
In what circumstances does findViewById()
return null?
Obviously, findViewById()
doesn't succeed in finding the layout resource but what could possibly explain this?
I'm going to go out on a limb and say that you did not call setContentView(R.layout.main) before calling that, which you must do.
You need to call setContentView before:
setContentView(R.layout.main);
精彩评论