Problem with serializate object to xml

When I try to check the app on phone, application is close. Is it right to serializate the object to xml file?

 namespace App
    {
        [Activity (Label = "App", MainLauncher = true, Icon = "@drawable/icon")]
        public class MainActivity : Activity
        {
            //int count = 1;
            Clicks obj ;

            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
                string sdcard=Android.OS.Environment.ExternalStorageDirectory.AbsolutePath+"/XMLSAVE.XML";
                Button button = FindViewById<Button> (Resource.Id.myButton);
            XmlSerializer forrmater = new XmlSerializer (typeof(Clicks));
            if (System.IO.File.Exists (sdcard)) {
            using (FileStream fs = new FileStream (sdcard, FileMode.OpenOrCreate)) {


            obj = (Clicks)forrmater.Deserialize (fs);
                }
                }
            else {
                        obj = new Clicks ();
                obj.click = 0;

            }


                button.Click += delegate {
                    button.Text = string.Format ("{0} clicks!",  sdcard);
                    obj.click++;
        using(FileStream fs =new FileStream(sdcard,FileMode.OpenOrCreate))
                    {
                    forrmater.Serialize(fs,obj);
            }
                };
            }
        }
        [Serializable]
        class Clicks{

            public int click{ get; set;}
        }
    }

Answers

  • CheesebaronCheesebaron DKInsider, University mod

    Stop creating multiple questions, stick to the one you have already made on this topic.

Sign In or Register to comment.