C# Xamarin Android . ButtonClick event help needed -


i tired doing simple a+b addition program using xamarin every time error system.nullreferenceexception occurs button click.

button button = findviewbyid<button>(resource.id.button1);         button.click += delegate {             edittext number1 = findviewbyid<edittext>(resource.id.edittext1);             edittext number2 = findviewbyid<edittext>(resource.id.edittext2);             textview res = findviewbyid<textview>(resource.id.textview1);             int result = convert.toint32(number1.text) + convert.toint32(number2.text);             res.text = result.tostring();         }; 

enter image description here

you commented out line:

setcontentview(resource.layout.main); 

this "binds" current activity content view. if dont bind program cant find elements button. gives object reference error.

so remove // infront of setcontentview , should work.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -