مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

esmael

عضویت از 1395/06/30

ساخت برنامه ماشین حساب با زامارین و ارور موجود

  • سه شنبه 30 شهریور 1395
  • 19:29
تشکر میکنم

سلام دوستان من یه برنامه نوشتم یه ماشین حساب اولین برنامم هست حالا یه ارور میگیره کدش این شکلی نوشتم

public class MainActivity : Activity
    {
        
        EditText editText1;
        EditText editText2;
        Button button1;
        TextView textview1;
        int a,b,c=1;
       
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

         

            // Get our button from the layout resource,
            // and attach an event to it

            button1 = FindViewById<Button>(Resource.Id.button1);
            textview1 = FindViewById<TextView>(Resource.Id.textView1);
            editText1 = FindViewById<EditText>(Resource.Id.editText1);
            editText2 = FindViewById<EditText>(Resource.Id.editText2);

         

            button1.Click += Button1_Click;
           

        }

        private void Button1_Click(object sender, EventArgs e)
        {

            a=Convert.ToInt32(editText1);
            b=Convert.ToInt32(editText1);
            c = a + b;
            textview1.Text=Convert.ToString(c);
        }

 

ممنون میشم ببینید مشکل چیه راستی ارور رو از متغییر های a,b میگیره راستی کد نویسیش درسته؟

پاسخ های این پرسش

تعداد پاسخ ها : 2 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • چهارشنبه 31 شهریور 1395
  • 09:09
  private void Button1_Click(object sender, EventArgs e)
        {
 
            a=Convert.ToInt32(editText1.Text);
            b=Convert.ToInt32(editText1.Text);
            c = a + b;
            textview1.Text=Convert.ToString(c);
        }

 

کاربر سایت

rashedk

عضویت از 1399/01/06

  • چهارشنبه 6 فروردین 1399
  • 20:26

سلام من هم یک سوال داشتم

System.NullReferenceException: Object reference not set to an instance of an object

دلیل این ارور چیه؟

Warning 1 Field 'calclutor.MainActivity.edittext1' is never assigned to, and will always have its default value null D:\p\calclutor\calclutor\MainActivity.cs 15 26 calclutor
کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)