안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요.
main.xml에서 지정한 object가 create되는 시점이 궁금합니다.
onCreate에서 setContentView명령어 전에 아래처럼 findViewbyId를 통해서 객체를 얻은 후에 access하면 null pointer에러가 나더군요.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = (Button)findViewById(R.id.Button01);
button.setOnClickListener(this);
//objects used in the main.xml are created dynamically here
setContentView(R.layout.main);
}
하지만 setContentView이후에 넣으면 Null pointer에러가 발생하지 않더군요.
main.xml같은 layout에서 사용된 객체가 생성되는 시점을 setContentView로 보면될까요?
정확히 언제 생성되는지 궁금하네요.
감사합니다.
main.xml에서 지정한 object가 create되는 시점이 궁금합니다.
onCreate에서 setContentView명령어 전에 아래처럼 findViewbyId를 통해서 객체를 얻은 후에 access하면 null pointer에러가 나더군요.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = (Button)findViewById(R.id.Button01);
button.setOnClickListener(this);
//objects used in the main.xml are created dynamically here
setContentView(R.layout.main);
}
하지만 setContentView이후에 넣으면 Null pointer에러가 발생하지 않더군요.
main.xml같은 layout에서 사용된 객체가 생성되는 시점을 setContentView로 보면될까요?
정확히 언제 생성되는지 궁금하네요.
감사합니다.