IObserver is missing methods












0















The Observable class already works, however I am still struggeling with the IObserver.



In the Xamarin documentation for the 'IObserver' it says, that I only have to implement the Update() method for the interface IObserver.



My problems:





  1. when I add the : IObserver I get an error that I do not implement these two methods:



            public IntPtr Handle => throw new NotImplementedException();

    public void Dispose()
    {
    throw new NotImplementedException();
    }


    Why do I need these methods and what are they for? They are not mentioned in the Xamarin documentation.



  2. When I add these methods, I get the follwing error message:
    error XA4212: Type firstTry3.bluetoothConnectionActivity/deviceFoundObserver implements Android.Runtime.IJavaObject but does not inherit Java.Lang.Object or Java.Lang.Throwable. This is not supported.


  3. When I add override to the update method, the compiler says that there is no suitable method to override



Here is my code:



        public class deviceFoundObserver : IObserver
{
bluetoothConnectionActivity mActivity;

public deviceFoundObserver(bluetoothConnectionActivity a)
{
mActivity = a;
}

//function is called from subject observable whenever a change happened
public override void Update(Observable observable, Java.Lang.Object data) //perhaps arguments like this: Observable observable, Object data
{
//there could be other messages as well, so first check wheather it is the right call from observer
if ((string)data == deviceName)
{
mActivity.buttonStartEKG.Visibility = ViewStates.Visible;
Log.Info(constants.tag, MethodBase.GetCurrentMethod().Name + ": Observable called update function in Observer");
}
}
}


I assume that I got something wrong in the way the Observer is used. Can anyone help me out?










share|improve this question



























    0















    The Observable class already works, however I am still struggeling with the IObserver.



    In the Xamarin documentation for the 'IObserver' it says, that I only have to implement the Update() method for the interface IObserver.



    My problems:





    1. when I add the : IObserver I get an error that I do not implement these two methods:



              public IntPtr Handle => throw new NotImplementedException();

      public void Dispose()
      {
      throw new NotImplementedException();
      }


      Why do I need these methods and what are they for? They are not mentioned in the Xamarin documentation.



    2. When I add these methods, I get the follwing error message:
      error XA4212: Type firstTry3.bluetoothConnectionActivity/deviceFoundObserver implements Android.Runtime.IJavaObject but does not inherit Java.Lang.Object or Java.Lang.Throwable. This is not supported.


    3. When I add override to the update method, the compiler says that there is no suitable method to override



    Here is my code:



            public class deviceFoundObserver : IObserver
    {
    bluetoothConnectionActivity mActivity;

    public deviceFoundObserver(bluetoothConnectionActivity a)
    {
    mActivity = a;
    }

    //function is called from subject observable whenever a change happened
    public override void Update(Observable observable, Java.Lang.Object data) //perhaps arguments like this: Observable observable, Object data
    {
    //there could be other messages as well, so first check wheather it is the right call from observer
    if ((string)data == deviceName)
    {
    mActivity.buttonStartEKG.Visibility = ViewStates.Visible;
    Log.Info(constants.tag, MethodBase.GetCurrentMethod().Name + ": Observable called update function in Observer");
    }
    }
    }


    I assume that I got something wrong in the way the Observer is used. Can anyone help me out?










    share|improve this question

























      0












      0








      0








      The Observable class already works, however I am still struggeling with the IObserver.



      In the Xamarin documentation for the 'IObserver' it says, that I only have to implement the Update() method for the interface IObserver.



      My problems:





      1. when I add the : IObserver I get an error that I do not implement these two methods:



                public IntPtr Handle => throw new NotImplementedException();

        public void Dispose()
        {
        throw new NotImplementedException();
        }


        Why do I need these methods and what are they for? They are not mentioned in the Xamarin documentation.



      2. When I add these methods, I get the follwing error message:
        error XA4212: Type firstTry3.bluetoothConnectionActivity/deviceFoundObserver implements Android.Runtime.IJavaObject but does not inherit Java.Lang.Object or Java.Lang.Throwable. This is not supported.


      3. When I add override to the update method, the compiler says that there is no suitable method to override



      Here is my code:



              public class deviceFoundObserver : IObserver
      {
      bluetoothConnectionActivity mActivity;

      public deviceFoundObserver(bluetoothConnectionActivity a)
      {
      mActivity = a;
      }

      //function is called from subject observable whenever a change happened
      public override void Update(Observable observable, Java.Lang.Object data) //perhaps arguments like this: Observable observable, Object data
      {
      //there could be other messages as well, so first check wheather it is the right call from observer
      if ((string)data == deviceName)
      {
      mActivity.buttonStartEKG.Visibility = ViewStates.Visible;
      Log.Info(constants.tag, MethodBase.GetCurrentMethod().Name + ": Observable called update function in Observer");
      }
      }
      }


      I assume that I got something wrong in the way the Observer is used. Can anyone help me out?










      share|improve this question














      The Observable class already works, however I am still struggeling with the IObserver.



      In the Xamarin documentation for the 'IObserver' it says, that I only have to implement the Update() method for the interface IObserver.



      My problems:





      1. when I add the : IObserver I get an error that I do not implement these two methods:



                public IntPtr Handle => throw new NotImplementedException();

        public void Dispose()
        {
        throw new NotImplementedException();
        }


        Why do I need these methods and what are they for? They are not mentioned in the Xamarin documentation.



      2. When I add these methods, I get the follwing error message:
        error XA4212: Type firstTry3.bluetoothConnectionActivity/deviceFoundObserver implements Android.Runtime.IJavaObject but does not inherit Java.Lang.Object or Java.Lang.Throwable. This is not supported.


      3. When I add override to the update method, the compiler says that there is no suitable method to override



      Here is my code:



              public class deviceFoundObserver : IObserver
      {
      bluetoothConnectionActivity mActivity;

      public deviceFoundObserver(bluetoothConnectionActivity a)
      {
      mActivity = a;
      }

      //function is called from subject observable whenever a change happened
      public override void Update(Observable observable, Java.Lang.Object data) //perhaps arguments like this: Observable observable, Object data
      {
      //there could be other messages as well, so first check wheather it is the right call from observer
      if ((string)data == deviceName)
      {
      mActivity.buttonStartEKG.Visibility = ViewStates.Visible;
      Log.Info(constants.tag, MethodBase.GetCurrentMethod().Name + ": Observable called update function in Observer");
      }
      }
      }


      I assume that I got something wrong in the way the Observer is used. Can anyone help me out?







      c# android xamarin.android observer-pattern






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 15:19









      MarkusNYMarkusNY

      105




      105
























          1 Answer
          1






          active

          oldest

          votes


















          0















          Why do I need these methods and what are they for? They are not
          mentioned in the Xamarin documentation.




          Let's have a look at definition of IObserver:



          namespace Java.Util
          {
          public interface IObserver : IJavaObject, IDisposable
          {
          void Update(Observable o, Lang.Object arg);
          }
          }


          The two methods is not mentioned here, however we can find out that IObserver inherits from IJavaObject and IDisposable. Then go to the definition of IJavaObject and IDisposable:



          namespace Android.Runtime
          {
          public interface IJavaObject : IDisposable
          {
          IntPtr Handle { get; }
          }
          }

          namespace System
          {
          public interface IDisposable
          {
          void Dispose();
          }
          }


          We can find the two methods here. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition. You should also implement the method defined in the IJavaObject and IDisposable.




          When I add these methods, I get the follwing error message: error
          XA4212:.....




          I did not get this error after add these methods. Try again and you can refer these similar questions:error-xa4212, implementing-java-interfaces.




          When I add override to the update method, the compiler says that there
          is no suitable method to override




          You should not add override to the update method. Just implement the method defined in the interface instead of override. You can have a look a interface definition here.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008847%2fiobserver-is-missing-methods%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0















            Why do I need these methods and what are they for? They are not
            mentioned in the Xamarin documentation.




            Let's have a look at definition of IObserver:



            namespace Java.Util
            {
            public interface IObserver : IJavaObject, IDisposable
            {
            void Update(Observable o, Lang.Object arg);
            }
            }


            The two methods is not mentioned here, however we can find out that IObserver inherits from IJavaObject and IDisposable. Then go to the definition of IJavaObject and IDisposable:



            namespace Android.Runtime
            {
            public interface IJavaObject : IDisposable
            {
            IntPtr Handle { get; }
            }
            }

            namespace System
            {
            public interface IDisposable
            {
            void Dispose();
            }
            }


            We can find the two methods here. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition. You should also implement the method defined in the IJavaObject and IDisposable.




            When I add these methods, I get the follwing error message: error
            XA4212:.....




            I did not get this error after add these methods. Try again and you can refer these similar questions:error-xa4212, implementing-java-interfaces.




            When I add override to the update method, the compiler says that there
            is no suitable method to override




            You should not add override to the update method. Just implement the method defined in the interface instead of override. You can have a look a interface definition here.






            share|improve this answer




























              0















              Why do I need these methods and what are they for? They are not
              mentioned in the Xamarin documentation.




              Let's have a look at definition of IObserver:



              namespace Java.Util
              {
              public interface IObserver : IJavaObject, IDisposable
              {
              void Update(Observable o, Lang.Object arg);
              }
              }


              The two methods is not mentioned here, however we can find out that IObserver inherits from IJavaObject and IDisposable. Then go to the definition of IJavaObject and IDisposable:



              namespace Android.Runtime
              {
              public interface IJavaObject : IDisposable
              {
              IntPtr Handle { get; }
              }
              }

              namespace System
              {
              public interface IDisposable
              {
              void Dispose();
              }
              }


              We can find the two methods here. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition. You should also implement the method defined in the IJavaObject and IDisposable.




              When I add these methods, I get the follwing error message: error
              XA4212:.....




              I did not get this error after add these methods. Try again and you can refer these similar questions:error-xa4212, implementing-java-interfaces.




              When I add override to the update method, the compiler says that there
              is no suitable method to override




              You should not add override to the update method. Just implement the method defined in the interface instead of override. You can have a look a interface definition here.






              share|improve this answer


























                0












                0








                0








                Why do I need these methods and what are they for? They are not
                mentioned in the Xamarin documentation.




                Let's have a look at definition of IObserver:



                namespace Java.Util
                {
                public interface IObserver : IJavaObject, IDisposable
                {
                void Update(Observable o, Lang.Object arg);
                }
                }


                The two methods is not mentioned here, however we can find out that IObserver inherits from IJavaObject and IDisposable. Then go to the definition of IJavaObject and IDisposable:



                namespace Android.Runtime
                {
                public interface IJavaObject : IDisposable
                {
                IntPtr Handle { get; }
                }
                }

                namespace System
                {
                public interface IDisposable
                {
                void Dispose();
                }
                }


                We can find the two methods here. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition. You should also implement the method defined in the IJavaObject and IDisposable.




                When I add these methods, I get the follwing error message: error
                XA4212:.....




                I did not get this error after add these methods. Try again and you can refer these similar questions:error-xa4212, implementing-java-interfaces.




                When I add override to the update method, the compiler says that there
                is no suitable method to override




                You should not add override to the update method. Just implement the method defined in the interface instead of override. You can have a look a interface definition here.






                share|improve this answer














                Why do I need these methods and what are they for? They are not
                mentioned in the Xamarin documentation.




                Let's have a look at definition of IObserver:



                namespace Java.Util
                {
                public interface IObserver : IJavaObject, IDisposable
                {
                void Update(Observable o, Lang.Object arg);
                }
                }


                The two methods is not mentioned here, however we can find out that IObserver inherits from IJavaObject and IDisposable. Then go to the definition of IJavaObject and IDisposable:



                namespace Android.Runtime
                {
                public interface IJavaObject : IDisposable
                {
                IntPtr Handle { get; }
                }
                }

                namespace System
                {
                public interface IDisposable
                {
                void Dispose();
                }
                }


                We can find the two methods here. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition. You should also implement the method defined in the IJavaObject and IDisposable.




                When I add these methods, I get the follwing error message: error
                XA4212:.....




                I did not get this error after add these methods. Try again and you can refer these similar questions:error-xa4212, implementing-java-interfaces.




                When I add override to the update method, the compiler says that there
                is no suitable method to override




                You should not add override to the update method. Just implement the method defined in the interface instead of override. You can have a look a interface definition here.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 3 at 2:53









                Jack Hua - MSFTJack Hua - MSFT

                1,184129




                1,184129
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008847%2fiobserver-is-missing-methods%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                    Npm cannot find a required file even through it is in the searched directory