Attempt to invoke virtual method void android.widget.Button.setonClickListner on a null object reference
I have checked my XML
file and all Buttons have correct id's, but this error persists.
Activity_main.java
e1=(EditText)findViewById(R.id.editText);
e1.setCursorVisible(false);
b1=(Button)findViewById(R.id.one);
b2=(Button)findViewById(R.id.two);
b3=(Button)findViewById(R.id.three);
b4=(Button)findViewById(R.id.four);
b5=(Button)findViewById(R.id.five);
b6=(Button)findViewById(R.id.six);
b7=(Button)findViewById(R.id.seven);
b8=(Button)findViewById(R.id.eight);
b9=(Button)findViewById(R.id.nine);
b0=(Button)findViewById(R.id.zero);
minus=(Button)findViewById(R.id.minus);
plus=(Button)findViewById(R.id.plus);
dot=(Button)findViewById(R.id.dot);
multi=(Button)findViewById(R.id.multi);
divide=(Button)findViewById(R.id.divide);
equals=(Button)findViewById(R.id.equals);
del=(Button)findViewById(R.id.del);
ac=(Button)findViewById(R.id.ac);
sqrt=(Button)findViewById(R.id.sqrt);
sin=(Button)findViewById(R.id.sin);
cos=(Button)findViewById(R.id.cos);
tan=(Button)findViewById(R.id.tan);
plusminus=(Button)findViewById(R.id.plusminus);
inverse=(Button)findViewById(R.id.inverse);
power=(Button)findViewById(R.id.power);
exp=(Button)findViewById(R.id.exp);
log=(Button)findViewById(R.id.log);
pie=(Button)findViewById(R.id.pie);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
b4.setOnClickListener(this);
b5.setOnClickListener(this);
b6.setOnClickListener(this);
b7.setOnClickListener(this);
b8.setOnClickListener(this);
b9.setOnClickListener(this);
b0.setOnClickListener(this);
minus.setOnClickListener(this);
plus.setOnClickListener(this);
dot.setOnClickListener(this);
multi.setOnClickListener(this);
divide.setOnClickListener(this);
equals.setOnClickListener(this);
del.setOnClickListener(this);
ac.setOnClickListener(this);
sqrt.setOnClickListener(this);
sin.setOnClickListener(this);
cos.setOnClickListener(this);
tan.setOnClickListener(this);
plusminus.setOnClickListener(this);
inverse.setOnClickListener(this);
power.setOnClickListener(this);
exp.setOnClickListener(this);
log.setOnClickListener(this);
pie.setOnClickListener(this);
}
Initialize your button before calling
setOnClickListener()