sample = (Button) findViewById(R.id.sampleButton);
sample.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
When I try to load my Activity, it throws a null pointer exception on the Listener. Why? I have defined my button variable globally.
Button sample;
Your button
sampleButtonis probably not in the layout you passed tosetContentView().findViewById()can only find views that are currently displayed.