Home > database >  Xamarin Binding Error CS0534: 'HttpGetRequest' does not implement inherited abstract membe
Xamarin Binding Error CS0534: 'HttpGetRequest' does not implement inherited abstract membe

Time:04-06

I want to use Triton Digital Mobile SDK on my Xamarin.Android project.

After creating the Binding Library and trying to build it, I get this error:

error CS0534: 'HttpGetRequest' does not implement inherited abstract member 'AsyncTask.DoInBackground(params Object[]?)'

I checked the contents of HttpGetRequest using a decompiler :

package com.tritondigital.util;

import android.os.AsyncTask;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpGetRequest extends AsyncTask<String, Void, String> {
  public static final String REQUEST_METHOD = "GET";
  
  public static final int READ_TIMEOUT = 15000;
  
  public static final int CONNECTION_TIMEOUT = 15000;
  
  protected String doInBackground(String... params) {
    String result, stringUrl = params[0];
    try {
      URL myUrl = new URL(stringUrl);
      HttpURLConnection connection = (HttpURLConnection)myUrl.openConnection();
      connection.setRequestMethod("GET");
      connection.setReadTimeout(15000);
      connection.setConnectTimeout(15000);
      connection.connect();
      connection.getResponseCode();
      InputStreamReader streamReader = new InputStreamReader(connection.getInputStream());
      BufferedReader reader = new BufferedReader(streamReader);
      StringBuilder stringBuilder = new StringBuilder();
      String inputLine;
      while ((inputLine = reader.readLine()) != null)
        stringBuilder.append(inputLine); 
      reader.close();
      streamReader.close();
      result = stringBuilder.toString();
    } catch (IOException e) {
      result = null;
    } 
    return result;
  }
  
  protected void onPostExecute(String result) {
    super.onPostExecute(result);
  }
}

This is the content of the file where the error is on the Xamarin Binding Library:

using System;
using System.Collections.Generic;
using Android.Runtime;
using Java.Interop;

namespace Com.Tritondigital.Util {

    // Metadata.xml XPath class reference: path="/api/package[@name='com.tritondigital.util']/class[@name='HttpGetRequest']"
    [global::Android.Runtime.Register ("com/tritondigital/util/HttpGetRequest", DoNotGenerateAcw=true)]
    public partial class HttpGetRequest : global::Android.OS.AsyncTask {
        // Metadata.xml XPath field reference: path="/api/package[@name='com.tritondigital.util']/class[@name='HttpGetRequest']/field[@name='CONNECTION_TIMEOUT']"
        [Register ("CONNECTION_TIMEOUT")]
        public const int ConnectionTimeout = (int) 15000;

        // Metadata.xml XPath field reference: path="/api/package[@name='com.tritondigital.util']/class[@name='HttpGetRequest']/field[@name='READ_TIMEOUT']"
        [Register ("READ_TIMEOUT")]
        public const int ReadTimeout = (int) 15000;

        // Metadata.xml XPath field reference: path="/api/package[@name='com.tritondigital.util']/class[@name='HttpGetRequest']/field[@name='REQUEST_METHOD']"
        [Register ("REQUEST_METHOD")]
        public const string RequestMethod = (string) "GET";

        static readonly JniPeerMembers _members = new XAPeerMembers ("com/tritondigital/util/HttpGetRequest", typeof (HttpGetRequest));

        internal static IntPtr class_ref {
            get { return _members.JniPeerType.PeerReference.Handle; }
        }

        [global::System.Diagnostics.DebuggerBrowsable (global::System.Diagnostics.DebuggerBrowsableState.Never)]
        [global::System.ComponentModel.EditorBrowsable (global::System.ComponentModel.EditorBrowsableState.Never)]
        public override global::Java.Interop.JniPeerMembers JniPeerMembers {
            get { return _members; }
        }

        [global::System.Diagnostics.DebuggerBrowsable (global::System.Diagnostics.DebuggerBrowsableState.Never)]
        [global::System.ComponentModel.EditorBrowsable (global::System.ComponentModel.EditorBrowsableState.Never)]
        protected override IntPtr ThresholdClass {
            get { return _members.JniPeerType.PeerReference.Handle; }
        }

        [global::System.Diagnostics.DebuggerBrowsable (global::System.Diagnostics.DebuggerBrowsableState.Never)]
        [global::System.ComponentModel.EditorBrowsable (global::System.ComponentModel.EditorBrowsableState.Never)]
        protected override global::System.Type ThresholdType {
            get { return _members.ManagedPeerType; }
        }

        protected HttpGetRequest (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer)
        {
        }

        // Metadata.xml XPath constructor reference: path="/api/package[@name='com.tritondigital.util']/class[@name='HttpGetRequest']/constructor[@name='HttpGetRequest' and count(parameter)=0]"
        [Register (".ctor", "()V", "")]
        public unsafe HttpGetRequest () : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
        {
            const string __id = "()V";

            if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero)
                return;

            try {
                var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null);
                SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef);
                _members.InstanceMethods.FinishCreateInstance (__id, this, null);
            } finally {
            }
        }

        static Delegate cb_doInBackground_arrayLjava_lang_String_;
#pragma warning disable 0169
        static Delegate GetDoInBackground_arrayLjava_lang_String_Handler ()
        {
            if (cb_doInBackground_arrayLjava_lang_String_ == null)
                cb_doInBackground_arrayLjava_lang_String_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_L) n_DoInBackground_arrayLjava_lang_String_);
            return cb_doInBackground_arrayLjava_lang_String_;
        }

        static IntPtr n_DoInBackground_arrayLjava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native__params)
        {
            var __this = global::Java.Lang.Object.GetObject<global::Com.Tritondigital.Util.HttpGetRequest> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
            var @params = (string[]) JNIEnv.GetArray (native__params, JniHandleOwnership.DoNotTransfer, typeof (string));
            IntPtr __ret = JNIEnv.NewString (__this.DoInBackground (@params));
            if (@params != null)
                JNIEnv.CopyArray (@params, native__params);
            return __ret;
        }
#pragma warning restore 0169

        // Metadata.xml XPath method reference: path="/api/package[@name='com.tritondigital.util']/class[@name='HttpGetRequest']/method[@name='doInBackground' and count(parameter)=1 and parameter[1][@type='java.lang.String...']]"
        [Register ("doInBackground", "([Ljava/lang/String;)Ljava/lang/String;", "GetDoInBackground_arrayLjava_lang_String_Handler")]
        protected virtual unsafe string DoInBackground (params string[] @params)
        {
            const string __id = "doInBackground.([Ljava/lang/String;)Ljava/lang/String;";
            IntPtr native__params = JNIEnv.NewArray (@params);
            try {
                JniArgumentValue* __args = stackalloc JniArgumentValue [1];
                __args [0] = new JniArgumentValue (native__params);
                var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, __args);
                return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef);
            } finally {
                if (@params != null) {
                    JNIEnv.CopyArray (native__params, @params);
                    JNIEnv.DeleteLocalRef (native__params);
                }
                global::System.GC.KeepAlive (@params);
            }
        }

        static Delegate cb_onPostExecute_Ljava_lang_String_;
#pragma warning disable 0169
        static Delegate GetOnPostExecute_Ljava_lang_String_Handler ()
        {
            if (cb_onPostExecute_Ljava_lang_String_ == null)
                cb_onPostExecute_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_V) n_OnPostExecute_Ljava_lang_String_);
            return cb_onPostExecute_Ljava_lang_String_;
        }

        static void n_OnPostExecute_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_result)
        {
            var __this = global::Java.Lang.Object.GetObject<global::Com.Tritondigital.Util.HttpGetRequest> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
            var result = JNIEnv.GetString (native_result, JniHandleOwnership.DoNotTransfer);
            __this.OnPostExecute (result);
        }
#pragma warning restore 0169

        // Metadata.xml XPath method reference: path="/api/package[@name='com.tritondigital.util']/class[@name='HttpGetRequest']/method[@name='onPostExecute' and count(parameter)=1 and parameter[1][@type='java.lang.String']]"
        [Register ("onPostExecute", "(Ljava/lang/String;)V", "GetOnPostExecute_Ljava_lang_String_Handler")]
        protected virtual unsafe void OnPostExecute (string result)
        {
            const string __id = "onPostExecute.(Ljava/lang/String;)V";
            IntPtr native_result = JNIEnv.NewString (result);
            try {
                JniArgumentValue* __args = stackalloc JniArgumentValue [1];
                __args [0] = new JniArgumentValue (native_result);
                _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
            } finally {
                JNIEnv.DeleteLocalRef (native_result);
            }
        }

    }
}

Any ideas on how to fix this?

CodePudding user response:

You can open the Metadata.xml under the Transforms folder, and add the following code:

<add-node path="/api/package[@name='com.tritondigital.util']">
  <class abstract="false" deprecated="not deprecated" final="false" name="HttpGetRequest" static="true" visibility="public" extends="java.lang.Object"/>
</add-node>

In addition, you can check the similar case follow and read the document about the binding.

Case:error CS0534: [java class] does not implement inherited abstract member 'AsyncTask.DoInBackground(params Object[])'

Document:https://gist.github.com/JonDouglas/dda6d8ace7d071b0e8cb#common-paths

  • Related