我是Android的学习者。如果单击按钮,我想String[]={"Rubin","Android","Steve"}
在 textview 中显示。
我收到空指针异常onClick
代码:
TextView tv;
Button b1;
String question[]={"Rubin","Android","Steve"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ques);
tv = (TextView) findViewById(R.id.button1);
b1 = (Button) findViewById(R.id.startExam);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
tv.setText(question[0]);
}
});
}