Java Question Signature does not match and missing types in IDE

tchart

Well-Known Member
Licensed User
Longtime User
Hi

I am stuck with part of a library I am writing/wrapping.

I keep getting a "signature does not match expected signature" error message.

But before we get into that I've tried to use the IDE auto completion for the events (from here) but my types dont show up. Is there something I need to do in my libary to get them to show up?

Ok, now back to the signature.

I have a couple of listeners like this which work fine;

B4X:
public void onSingleTap(float x, float y)
{
   ba.raiseEventFromUI(this, eventName + "_onsingletaplistener", new Object[] { x,y });
       Log.i("B4A", eventName + "_onsingletaplistener");
}

And the corresponding code in B4A

B4X:
Sub MapView1_OnSingleTapListener(x As Float, y As Float)
   ToastMessageShow("X " & x & " / Y " & y, False)

So no problem there.

Now the one I do have issue with is this one. FeatureSet is a custom type.

B4X:
public void onCallback(FeatureSet fSet)
{
   eventBa.raiseEventFromUI(this, eventName + "_selectoncallback", new Object[] { fSet });
   Log.i("B4A", eventName + "_selectoncallback");
}

Now in B4A I have this defined

B4X:
Sub feature_layer_SelectOnCallback(fSet As  FeatureSet)
   ToastMessageShow("Here!", False)
   ToastMessageShow(fSet.DisplayFieldName, False)
End Sub

But I keep getting the signature error?

Is there something special I need to do because there is only one return object or is it to do with the custom type?

Any help appreciated :)
 

tchart

Well-Known Member
Licensed User
Longtime User
Right, so I found the problem but dont know how to fix it.

The generated code is this;

B4X:
public static String  _feature_layer_selectoncallback(com.tchart.ags.proxy.core.map.FeatureSetWrapper _fset)

So the signature of the B4A code is for a FeatureSetWrapper but the raiseevent is sending through a FeatureSet.

Any ideas how to resolve this mismatch?
 

thedesolatesoul

Expert
Licensed User
Longtime User
I guess you need to update this code to return the featuresetwrapper:

public void onCallback(FeatureSet fSet)
{
eventBa.raiseEventFromUI(this, eventName + "_selectoncallback", new Object[] { fSet });
Log.i("B4A", eventName + "_selectoncallback");
}

You can create a new one.
Something like this (I havent tried this, it is just a concept):


com.tchart.ags.proxy.core.map.FeatureSetWrapper fsetwrapper;
fsetwrapper.setObject(fSet)
eventBa.raiseEventFromUI(this, eventName + "_selectoncallback", fsetwrapper );
 

tchart

Well-Known Member
Licensed User
Longtime User
I guess you need to update this code to return the featuresetwrapper:

Thanks thedesolatesoul! That worked :)

B4X:
com.tchart.ags.proxy.core.map.FeatureSetWrapper fSetWrapper = new com.tchart.ags.proxy.core.map.FeatureSetWrapper();
fSetWrapper.setObject(fSet);
eventBa.raiseEventFromUI(null, eventName + "_selectoncallback", new Object[] { fSetWrapper });
 

tchart

Well-Known Member
Licensed User
Longtime User
It did?! :icon_clap:

I do have some questions myself though.

First, how did you manager to define the same custom type in java?
Second, why do you return new Object[] {fsetWrapper}, does that return a new object or still the same one?

thedesolatesoul, Im still bumbling my way through this library business myself )Im no Java developer). Im wrapping a library which has many custom types.

Im not sure of the why the "new Object[]" bit is required but its in the other libraries Ive seen. Maybe its required when returning multiple values - so perhaps I dont need it for a single object?

Heres an example of a wrapper type;

B4X:
package com.tchart.ags.proxy.core.geometry;

import anywheresoftware.b4a.BA;
import com.esri.core.geometry.Point;
import anywheresoftware.b4a.AbsObjectWrapper;

@BA.Author("Trevor Hart")
@BA.ShortName("Point")

public class PointWrapper  extends AbsObjectWrapper<Point>
{
   public PointWrapper()
   {      
   }
   
   public PointWrapper(Point pPoint)
   {
      setObject(pPoint);
   }
     
   public PointWrapper(double x, double y) 
   {
      setObject(new Point(x, y));
   }
      
   public void Initialize (double x, double y)
   {
      setObject(new Point(x,y));      
   }

   public double getX()
   {
       return ((Point)getObject()).getX();
   }     

   public double getY()
   {
       return ((Point)getObject()).getY();
   }   
}

This has been working fine but I've run into a few issue with events and passing back custom types.
 

agraham

Expert
Licensed User
Longtime User
Im not sure of the why the "new Object[]" bit is required but its in the other libraries Ive seen.
It's a way of passing the required parameters to different event Subs with different signatures and so avoiding a multiplicity of raise event methods.
so perhaps I dont need it for a single object?
Yes you do because all of the raise event methods expect an Object array.
 
Top