2016-10-25 21 views
0

私はVisual StudioでXamarinの初心者です。 Jarファイル(SDK)を追加しなければならない既存のxamarin androidプロジェクトがあるので、Binding Libraryを作成しましたが、Metadata.xmlを使用して解決しようとしているいくつかのエラーが発生しています。次のように存在しているインタフェースでエラーCS0535クラスがインターフェイスメンバを実装していません

<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> 

'DeviceService' はapi.xmlに検索インタフェースのメンバーのIDeviceService.SetSignResult(int型) "

を実装していない私はこれを見つけましたそのような方法:

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); 
     } 

私は、この発見生成されたクラス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 { 
       } 
      } 
     } 

を誤っ、メソッドの実装や戻り値の型を推論私は知らない、とapi.xmlにそれを見て正しい方法であるようです:void setSignResult(int p0)。私は同じエラーでのmetadata.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> 

、一見で取る、前述と同様のがそれと比較すると、私はそれが正しくメソッドを生成しました:

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 { 
      } 
     } 

すぐにお手伝いが必要です。

+0

"IntPtr id_setSignResult_I;"関数の中に?関数の外にあるときに代理人がそれを設定する必要があるようです。また、私は問題のある関数には欠けているレジスタ宣言を別の関数で見ています。 –

+0

いいえ、IntPtr id_setSignResult_Iを動かすことができませんでした。同じエラー。 –

+0

[登録]属性はどうですか?なぜSetSignResultはBcrSymbologyToTextにそれがないのですか? –

答えて

0

見つかり答え:

ジェネレータをバインドXamarinは、(バインディングライブラリで動作します誰が)、JavaクラスからC#クラスに間違った方法でそれがreingenieering実行することはできませんいくつかのJavaコードを翻訳しているので、発電機が作成されますJavaメソッドのプロパティ結果としてsetSignResultこれらの問題を修正する方法は、いくつかのタイプのエラーに対してmetadata.xmlを使用することです。私の場合、同じ自動生成クラス名を持つ部分クラスを作成して欠落したメソッドを実装します。バインディングジェネレーターは独自の実装でDeviceService部分クラスを作成しましたので、私は実装を次のように欠けているメソッドを実装する別のDeviceService部分クラスを作成しました:

public partial class DeviceService 
    { 
     public void SetSignResult(int p) 
     { 
      SignResult = p; 
     } 
} 
完璧な作品

ありがとうございました

関連する問題