2010-03-02 5 views
5
<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) { 
} 

nullpointer 예외가 있습니다.android textview settext nullpointer 예외 표시

이것에 대한 해결책 것입니다. 그럼 나에게

답변

6

을 회신 해 주시기 바랍니다, 그 findViewById 반환 null을 보인다. this이 활동을 참조하지 않습니다 또는 onCreate의 활동에보기를 할당하지 않는 때문에 이것은 아마의 경우 (당신은 onCreate에서 setContentView를 호출해야합니다).

+0

감사합니다, 샘플을 가지고 있습니까 – saravanan

+1

감사합니다 jleedev, 나는 실제로 setcontentview 메서드 위치를 혼란 출력을 가지고있어. 이제 나는 깨끗이 해졌다. – saravanan