简体   繁体   English

错误CS0535类未实现接口成员

[英]error CS0535 Class does not implement interface member

I'm newbie in Xamarin with Visual Studio. 我是使用Visual Studio的Xamarin的新手。 There is an existing xamarin android project in which I had to add a Jar files (SDK), so I created a Binding Library, however it's throwing some errors that I'm trying to solve them by using Metadata.xml, one of them is as follows: 有一个现有的xamarin android项目,我不得不在其中添加一个Jar文件(SDK),因此我创建了一个绑定库,但是它抛出了一些错误,我试图通过使用Metadata.xml来解决它们,其中一个是如下:

'DeviceService' does not implement interface member 'IDeviceService.SetSignResult(int)' 'DeviceService'未实现接口成员'IDeviceService.SetSignResult(int)'

Searching into api.xml I've found this: 搜索api.xml我发现了这一点:

<class abstract="false" deprecated="not deprecated" extends="android.app.Service" extends-generic-aware="android.app.Service" final="false" name="DeviceService" static="false" visibility="public">
<implements name="com.company.deviceService.IDeviceService" name-generic-aware="com.company.deviceService.IDeviceService">
</implements>
<constructor deprecated="not deprecated" final="false" name="DeviceService" static="false" type="com.company.deviceService.DeviceService" visibility="public">
</constructor>
...
<method abstract="false" deprecated="not deprecated" final="false" name="setSignResult" native="false" return="void" static="false" synchronized="false" visibility="public">
<parameter name="p0" type="int">
</parameter>
</method>

<method abstract="false" deprecated="not deprecated" final="false"   name="getSignResult" native="false" return="int" static="false" synchronized="false" visibility="public">
</method>
...
</class>

In the Interface there is such method: 在接口中有这样的方法:

IntPtr id_setSignResult_I;
        public unsafe void SetSignResult (int p0)
        {
            if (id_setSignResult_I == IntPtr.Zero)
                id_setSignResult_I = JNIEnv.GetMethodID (class_ref, "setSignResult", "(I)V");
            JValue* __args = stackalloc JValue [1];
            __args [0] = new JValue (p0);
            JNIEnv.CallVoidMethod (Handle, id_setSignResult_I, __args);
        }

However when I search into generated class DeviceService.cs I found this: 但是,当我搜索生成的类DeviceService.cs时,发现了这一点:

static Delegate cb_setSignResult_I;
#pragma warning disable 0169
        static Delegate GetSetSignResult_IHandler ()
        {
            if (cb_setSignResult_I == null)
                cb_setSignResult_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_SetSignResult_I);
            return cb_setSignResult_I;
        }

        static void n_SetSignResult_I (IntPtr jnienv, IntPtr native__this, int p0)
        {
            global::com.company.deviceService.DeviceService __this = global::Java.Lang.Object.GetObject<global::com.company.deviceService.DeviceService> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
            __this.SignResult = p0;
        }
#pragma warning restore 0169

        static IntPtr id_getSignResult;
        static IntPtr id_setSignResult_I;

        public virtual unsafe int SignResult {
            // Metadata.xml XPath method reference: path="/api/package[@name='com.company.deviceService']/class[@name='DeviceService']/method[@name='getSignResult' and count(parameter)=0]"
            [Register ("getSignResult", "()I", "GetGetSignResultHandler")]
            get {
                if (id_getSignResult == IntPtr.Zero)
                    id_getSignResult = JNIEnv.GetMethodID (class_ref, "getSignResult", "()I");
                try {

                    if (GetType () == ThresholdType)
                        return JNIEnv.CallIntMethod  (Handle, id_getSignResult);
                    else
                        return JNIEnv.CallNonvirtualIntMethod  (Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "getSignResult", "()I"));
                } finally {
                }
            }
            // Metadata.xml XPath method reference: path="/api/package[@name='com.company.deviceService']/class[@name='DeviceService']/method[@name='setSignResult' and count(parameter)=1 and parameter[1][@type='int']]"
            [Register ("setSignResult", "(I)V", "GetSetSignResult_IHandler")]
            set {
                if (id_setSignResult_I == IntPtr.Zero)
                    id_setSignResult_I = JNIEnv.GetMethodID (class_ref, "setSignResult", "(I)V");
                try {
                    JValue* __args = stackalloc JValue [1];
                    __args [0] = new JValue (value);

                    if (GetType () == ThresholdType)
                        JNIEnv.CallVoidMethod  (Handle, id_setSignResult_I, __args);
                    else
                        JNIEnv.CallNonvirtualVoidMethod  (Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "setSignResult", "(I)V"), __args);
                } finally {
                }
            }
        }

For some reason Binding Generator incorrectly infer method implementation or return type, I don't know, and looking into api.xml it seems to be in correct way: void setSignResult (int p0). 出于某种原因,绑定生成器错误地推断了方法的实现或返回类型,我不知道,并且在api.xml中进行查找似乎是正确的方法:void setSignResult(int p0)。 I tried to modify behaviour by using metadata.xml with same error: 我试图通过使用具有相同错误的metas.xml来修改行为:

  <attr path="/api/package[@name='Com.Company.deviceservice']/class[@name='DeviceService']/method[@name='SetSignResult' 
    and count(parameter)=1
    and parameter[1][@type='int']]/parameter[1]"
    name="managedReturn">Java.Lang.Void</attr>

I looked for another Interface method implementation, similar to before mentioned to compare with it, and I found it correctly generates the method, take at look: 我寻找了另一个Interface方法的实现,类似于之前提到的与之比较的结果,我发现它正确地生成了该方法,请看一下:

static IntPtr id_bcrSymbologyToText_I;
        [Register ("bcrSymbologyToText", "(I)Ljava/lang/String;", "GetBcrSymbologyToText_IHandler")]

        public virtual unsafe string BcrSymbologyToText (int p0)
        {
            if (id_bcrSymbologyToText_I == IntPtr.Zero)
                id_bcrSymbologyToText_I = JNIEnv.GetMethodID (class_ref, "bcrSymbologyToText", "(I)Ljava/lang/String;");
            try {
                JValue* __args = stackalloc JValue [1];
                __args [0] = new JValue (p0);

                if (GetType () == ThresholdType)
                    return JNIEnv.GetString (JNIEnv.CallObjectMethod  (Handle, id_bcrSymbologyToText_I, __args), JniHandleOwnership.TransferLocalRef);
                else
                    return JNIEnv.GetString (JNIEnv.CallNonvirtualObjectMethod  (Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "bcrSymbologyToText", "(I)Ljava/lang/String;"), __args), JniHandleOwnership.TransferLocalRef);
            } finally {
            }
        }

Please need your help soon! 请尽快需要您的帮助!

Found answer: 找到答案:

Xamarin Binding Generator (Who Works on a Binding Library), are translating in wrong way from java classes to c# classes some java code that it can't perform reingenieering, so generator is creating a setSignResult as a property result from a java method. Xamarin绑定生成器(在绑定库上工作的人)正在以错误的方式将Java类无法转换的某些Java代码转换为c#类,因此生成器将setSignResult创建为java方法的属性结果。 The way to fix those things is using metadata.xml for some type of errors or else, implementing, in my case, the missing method by creating a partial class with same autogenerated class name. 解决这些问题的方法是将meta.xml用于某种类型的错误,否则,通过创建具有相同自动生成的类名的部分类来实现丢失的方法。 Since Binding Generator created DeviceService partial class with its own implementation, I created another DeviceService partial class implementing missing method with following implementation: 由于绑定生成器使用其自己的实现创建了DeviceService部分类,因此我创建了另一个DeviceService部分类,该类通过以下实现来实现缺少的方法:

public partial class DeviceService
    {
        public void SetSignResult(int p)
        {
            SignResult = p;
        }
}

Works perfect! 完美的作品!

thanks to all 谢谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 静态成员类无法实现接口 - Static member class cannot implement an interface class中的接口方法没有实现吗? - Interface methods in a class that does not implement it? 在主类中的实现接口上出现错误 - error on Implement interface in main class Xamarin 绑定错误 CS0534:“HttpGetRequest”未实现继承的抽象成员“AsyncTask.DoInBackground(params Object[]?)” - Xamarin Binding Error CS0534: 'HttpGetRequest' does not implement inherited abstract member 'AsyncTask.DoInBackground(params Object[]?)' 必须扩展A类并实现某些接口的成员变量 - Member variable which must extend class A and implement some interface 类 SpringHibernateJpaPersistenceProvider 没有实现请求的接口 PersistenceProvider - Class SpringHibernateJpaPersistenceProvider does not implement the requested interface PersistenceProvider 为什么ZonedDateTime类没有实现TemporalAdjuster接口 - why ZonedDateTime class does not implement TemporalAdjuster interface Map 接口是否扩展或实现了一些其他接口或 class? - Does Map interface extend or implement some other interface or class? 错误:预期的类、接口或枚举(实现 java) - error: class, interface, or enum expected (implement java) 将最终类强制转换为该类未声明要实现的兼容接口 - Cast a final class to a compatible interface that the class does not claim to implement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM