由网友(対伱、卟奢望)分享简介:
<TextView
android:id="@+id/first_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/black"
android:textColor="@color/light_grey"
android:text="FirstName"
></TextView>
TextView first_text_view;
first_text_view = (TextView)this.findViewById(R.id.first_name);
try {
first_text_view.setText("Android");
}catch(Exception e) {
}
我得到了空指针异常。
i got the nullpointer exception.
什么是这个解决方案。请回复我
what is solution for this. please reply me
推荐答案
唉,看来 findViewById
返回空
。这可能是这样,因为这
不请参考活动或者你并没有使用视图到活动中的onCreate
(你必须调用的setContentView
在的onCreate
)。
Well, seems that findViewById
returns null
. This is probably the case, because this
does not refer to the Activity or you're not assigning the View to the Activity in onCreate
(you have to call setContentView
in onCreate
).
相关推荐
最新文章