NullPointerException on Button.findViewById()

You are invoking the findViewById() method in the wrong way. It should be invoked on the Activity itself, not on the Button reference. Replace

b1=(Button) b1.findViewById(R.id.button);

with

b1=(Button) findViewById(R.id.button);

The b1 reference is null at that point, and is the reason for the NullPointerException.

Leave a Comment