Skip to content

C# to Java wrong translation for constructor #3490

@EmilAlipiev

Description

@EmilAlipiev

I am trying to create Samsung Tizen Companion app in Xamarin.Android. Samsung has an SDK called Samsung Accessory SDK. This is only available in jar. So I created a Java Binding Library.
Samsung also has a sample code in java how to handle communication between Tizen and Android (in this case xamarin.android).
So I tried to convert below attached java class(ProviderService.txt) into C# see the url
ProviderService.txt

Problem here is

below code constructor in C#


[Service(Exported = true, Name = "WearCompanion.Droid.ProviderService")]
    public class ProviderService : SAAgent 
    {   

        public ProviderService() : base("ProviderService", SASOCKET_CLASS)
        {

        }

when I look at the obj folder of my xamarin.android project and find ProviderClass.java file generated

public class ProviderService
    extends com.samsung.android.sdk.accessory.SAAgent
    implements
        mono.android.IGCUserPeer
{

    public ProviderService (java.lang.String p0, java.lang.Class p1)
    {
        super (p0, p1);
        if (getClass () == ProviderService.class)
            mono.android.TypeManager.Activate ("WearCompanion.Droid.ProviderService, WearCompanion.Android", "System.String, mscorlib:Java.Lang.Class, Mono.Android", this, new java.lang.Object[] { p0, p1 });
    }

but it is supposed to be interpreted as below java code

public class ProviderService extends SAAgent {
    private static final String TAG = "HelloAccessory(P)";
    private static final Class<ServiceConnection> SASOCKET_CLASS = ServiceConnection.class;

    public ProviderService() {
        super(TAG, SASOCKET_CLASS);
    }

in C# obviously no difference between 2 code pieces but in Java i think that there is difference because. Sdk request is failing with error telling me that

java.lang.InstantiationException: java.lang.Class has no zero argument constructor

Repro:
https://github.com/EmilAlipiev/SamsungWearCompanion

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions