Java Question Sub myzx_result signature does not match expected signature.

Johan Schoeman

Expert
Licensed User
Longtime User
I am trying to return the scanned bitmap image from the Zxing library to the B4A project but I am getting the following error:

java.lang.Exception: Sub myzx_result signature does not match expected signature.

I have added the following code (in red) to method handleDecode in class CaptureActivity:

public void handleDecode(Result obj, Bitmap barcode) {
inactivityTimer.onActivity();
viewfinderView.drawResultBitmap(barcode);
Log.i("B4A", obj.getBarcodeFormat().toString()+":"+obj.getText()+"###"+b4aZXingLib.en+"_result");
Intent data=new Intent();
data.putExtra("atype", obj.getBarcodeFormat().toString());
ByteArrayOutputStream stream = new ByteArrayOutputStream();

barcode.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
data.putExtra("image",byteArray);

Changed the following in class b4aZXingLib

//@Events(values={"result(atype as String,Value as String)"})

@Events(values={"result(atype as String,Value as String, image as Bitmap)","noscan(atype as String, Value as String, image as Bitmap)"})


Also added the following code to method ResultArrived in class b4aZXingLib (in red):

public void BeginScan(BA ba,String EventName) {
myba=ba;
en=EventName.toLowerCase();
Intent izx;
izx=new Intent(BA.applicationContext, CaptureActivity.class);
ion=new IOnActivityResult()
{

@override
public void ResultArrived(int arg0, Intent arg1) {
String atype;
String Value;
Bitmap image; //added

atype = "";
Value = "";
image = null; //added

if (arg0==-1){

atype=arg1.getStringExtra("atype");
Value=arg1.getStringExtra("value");
byte[] byteArray = arg1.getByteArrayExtra("image");

image = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

myba.raiseEvent2(null, false, en+"_result", true, new Object[]{atype,Value,image}); //added image

} else {
atype = "Null";
Value = "Null";
image = null;

myba.raiseEvent2(null, false, en+"_noscan", true, new Object[]{atype,Value,image}); //added image

}
}
};
ba.startActivityForResult(ion, izx);
}

The B4A sub is as follows:

B4X:
Sub myzx_result(atype As String, Value As String, image As Bitmap)
    ImageView1.Bitmap = image
    Log("type:" & atype &  "Value:" & Value)
    Msgbox(Value,"type:" & atype)

End Sub

I return a String, String, and Bitmap (in that order) from the library. Why the "signature does not match expected signature" error? The scanner scans but does not fire "Sub myzx_result" and then generates the error.


Some pointers/assistance will be very much appreciated.






 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
You need to convert it to BitmapWrapper and pass BitmapWrapper:
B4X:
BitmapWrapper bw = new BitmapWrapper();
bw.setObject(image);
Erel, can you please give a short explanation as to why the bitmap has to be passed from the library to the B4A project via the BitmapWrapper? How do the two bitmaps differ from one another that it requires the library bitmap to go via the BitmapWrapper to the B4A project?

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4A Bitmap is actually BitmapWrapper. As this class is a thin wrapper and it inherits from AbsObjectWrapper the compiler will convert it automatically for you in most cases. It cannot do it with event parameters so you must pass the correct type.

For example if you have passed a regular Bitmap and changed the B4A code to:
B4X:
Sub myzx_result(atype As String, Value As String, oimage As Object)
 Dim image As Bitmap = oimage
End Sub
Then it would have worked (though the better solution is to convert it yourself in the Java code).
 
Top