<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) {
}
Run Code Online (Sandbox Code Playgroud)
我得到了nullpointer异常.
什么是解决方案.请回复我
好吧,好像findViewById回来了null.这大概就是这样,因为this不请参考活动,或者你没有指定的视图中的活动onCreate(你必须调用setContentView的onCreate).
| 归档时间: |
|
| 查看次数: |
7594 次 |
| 最近记录: |