Although to handle the errors, you would need to use a
try...catch
block, whereas in this case it would be an
if...else
block to be used.
ButtonPrev = FindViewById<Button>(Resource.Id.buttonPrev);
ButtonNext = FindViewById<Button>(Resource.Id.buttonNext);
TextTitle = FindViewById<TextView>(Resource.Id.textTitle);
if(ButtonPrev != null) {
ButtonPrev.Click += ButtonPrev_Click;
}
This way, you will make sure that the event handlers are only associated if the objects exist, because if the buttons do not exist — there are several reasons for this, such as wrong ID being used, buttons not available in current layout, problem inflating the layout, ID different etc. — you do not need to even implement any handler on them. That would also make sure that the errors do not get raised.
The main error
Whereas, the main problem in your code is that you have commented out the layout; if the layout is included, and the button exists, there is no way that a button would end up null. Where as, in your code, you have intentionally done that.
Uncomment this line, and it would work.