我在布局中创建了一个按钮,当我测试时可以在屏幕上显示。我为这个按钮添加了click事件,但是就会接收到NullPointerException
错误信息。用的以下的代码:
Button b1;
int REQUEST_CODE =1;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
b1 = (Button) findViewById(R.id.web_button);
b1.setOnClickListener(new OnClickListener() { //ERROR THIS LINE
public void onClick(View arg0){}
});
setContentView(R.layout.intent);
}
哪里出错了呢?