由网友(爱莪者昌、毁莪者亡)分享简介:我有这个看似无辜的 findViewById()在我的的onCreate()这使返回null:I have this seemingly innocent findViewById() in my onCreate() which keeps returning null:mCheckLicenseButton =...
我有这个看似无辜的 findViewById()
在我的的onCreate()
这使返回null:
I have this seemingly innocent findViewById()
in my onCreate()
which keeps returning null:
mCheckLicenseButton = (Button) findViewById(R.id.btn_checkout);
我的 RES /布局/ main.xml中
clearnly包含此按钮:
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="wrap_content"
android:layout_below="@+id/top_textview"
android:layout_alignParentRight="true"
android:text="Check License" />
所以我不明白为什么 findViewById()
返回null。
在什么情况下 findViewById()
返回NULL?
In what circumstances does findViewById()
return null?
显然, findViewById()
寻找布局资源不会成功,但究竟是什么导致何解释?
Obviously, findViewById()
doesn't succeed in finding the layout resource but what could possibly explain this?
推荐答案
我会打电话说,你必须这样做才出门的肢体,并说你没有调用的setContentView(R.layout.main)
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.
相关推荐
最新文章