does not implement interface member 'IComparable.CompareTo(Object)'

我的梦境 提交于 2019-12-06 05:22:09

问题


I have an .aar file of android. I am trying to use it in my xamarin.android app. I followed the steps from the given in the link https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/binding-an-aar/

but when I am trying to build my library I am getting following error

"does not implement interface member 'IComparable.CompareTo(Object)'"

I found some solution for it where it is mentioned that in metadata.xml we need to add some attribute. so I added the following line there

path="/api/package[@name='com.logicjunction.ljindoorandroidsdk']/class[@name='FloorPlanBeaconsMapping']/implements[@name='java.lang.Comparable']" 

name="type">java.lang.Comparable>

But still getting same error. How I can fix this?


回答1:


Getting the error when build the library without interface implementation IComparable.CompareTo:

To resolve the issue, need create at "Additions" folder a partial class of the library class that requires interface member implementation 'IComparable.CompareTo(Object)', like below:

The namespace should be the same like at binding library, in this case, it is: "Hirondelle.Date4j".

using Java.Lang;
namespace Hirondelle.Date4j
{
    public partial class DateTime : Object, IComparable
    {
        int IComparable.CompareTo(Object obj)
        {
            return CompareTo((DateTime)obj);
        }
    }
}

Then the library should be built with success.




回答2:


So I had the same problem which I could solve it by helping the compiler in adding those lines in Metada.xml (Transforms folder) :

<add-node path="/api/package[@name='<JAVA_PACKAGE_NAME>']/class[@name='<CLASS_NAME>']">
    <method name="compareTo" return="int" abstract="false" native="false" synchronized="false" static="false" final="false" deprecated="not deprecated" visibility="public">
        <parameter name="p0" type="java.lang.Object" />
    </method>
</add-node>


来源:https://stackoverflow.com/questions/46337814/does-not-implement-interface-member-icomparable-comparetoobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!