1

I created an Android Binding Library for my Xamarin project, using an AAR.

I am now trying to implement that library.

Here is the java snippet of code using the library:

The java code:

new AsyncOperation.CompletionHandler<RouteManager>(){
    @Override
    public void success(RouteManager result){
        result.subscribe(ACCEL_DATA, new RouteManager.MessageHandler(){
        @Override
        public void process(Message message){
            Log.i(LOG_TAG,message)
        }
    }
}

I am trying to port this code to C#.

My C# code, from C# wrapper created from binding library:

class AsyncOperationHandler : AsyncOperationCompletionHandler
{
     public override unsafe void Success(Object p0)
     {
          try
          {
               var routeManger = (IRouteManager)p0;
               routeManger.Subscribe(ACCEL_DATA, new RouteMessageHandler());
          }
          catch (Exception)
          {
            Log.Error(LOG_TAG, "Error");
          }
     }
}

class RouteMessageHandler : IRouteManagerMessageHandler
{
      public void Dispose()
      {
          throw new NotImplementedException();
      }
      public IntPtr Handle { get; }
      public void Process(Message p0)
      {
          var message = p0;
          Log.Info(LOG_TAG, message);
      }
}

I am getting an error in the C# wrapper on the routeManger.Subscribe line.

When the RouteManagerMessageHandler gets initialized, it gets the Handle, then throws a null pointer exception inside the Binding Library.

Is this the correct way to port a Java Interface to C#?

1 Answer 1

2

If you implement a Java Interface, you have to derive from Java.Lang.Object.

class RouteMessageHandler : Java.Lang.Object, IRouteManagerMessageHandler
{
    public void Process(Message p0)
    {
        var message = p0;
        Log.Info(LOG_TAG, message);
    }
}

There should be something on the compile output.

Type 'AppXYZ.RouteMessageHandler' implements IRouteManagerMessageHandler but does not inherit from Java.Lang.Object. It is not supported.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.