B4J Question B4X (Barcode App runs on B4A and not B4J) - Solved

LGS

Member
Licensed User
Longtime User
Hello everyone.
I have a development in B4X that runs without problem in B4A, but not in B4J.
Initially sub drawEAN13 returned (Bitmap), but since B4J doesn't recognize Bitmap, I had to change it to B4XBitmap and with that change it also runs without problem in B4A.

Sub drawEAN13 (data As String, FondoBarras As Int,Barras As Int) As B4XBitmap 'Bitmap

I comment this because in line java, the drawEAN13 procedure is defined as Bitmap
public Bitmap drawEAN13
So it returns a Bitmap
I don't know if this is the source of the error when compiling in B4J

#AdditionalJar: core-3.2.1 is used in B4A and B4J
#AdditionalJar: C:\Android\platforms\android-33\android.jar is used in B4J

Log:
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Error occurred on line: 17 (EAN13)
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at b4j.example.ean13._drawean13(ean13.java:84)
    at b4j.example.b4xmainpage._creacodigobarra(b4xmainpage.java:162)
    at b4j.example.b4xmainpage._button1_click(b4xmainpage.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA$1.run(BA.java:236)
    at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
[B]Caused by: java.lang.RuntimeException: Stub![/B]
    at android.graphics.Bitmap.createBitmap(Bitmap.java:63)
    at b4j.example.ean13.encodeAsBitmap(ean13.java:123)
    at b4j.example.ean13.drawEAN13(ean13.java:109)
    ... 29 more

I appreciate all the support and suggestions.
I attach sample code
 

Attachments

  • BC_B4A.zip
    277.9 KB · Views: 47
  • BC_B4J.zip
    270.8 KB · Views: 61
Solution
import android.graphics.Bitmap;

Any class imported from android will not work in B4J. There are examples in the B4J forum using the ZXING core classes that can also be used in B4J as none of those classes depend on android classes.

MarcoRome

Expert
Licensed User
Longtime User
i dont think tht android.jar can run on windows systems.
Anyway do you see:

 
Upvote 0

LGS

Member
Licensed User
Longtime User
Thanks for the support.

Initially this code was just B4A, then I made a few small changes to try to reuse the code to B4X.
But when compiling in B4J, I got the following error:
src\b4j\example\ean13.java:4: error: package android.graphics does not exist
import android.graphics.Bitmap;

Then in the forum I found the following:
https://www.b4x.com/android/forum/threads/how-do-i-import-android-graphics-bitmap.72656/post-462539

And following that suggestion I am trying to add the android.jar library like this:
#AdditionalJar: C:\Android\platforms\android-33\android.jar

I don't know if it is the correct way to add the library and also if it is possible to use it in B4J.

I'm just trying to adapt the code to B4X (if possible)

Thanks for the contributions 🤝
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
import android.graphics.Bitmap;

Any class imported from android will not work in B4J. There are examples in the B4J forum using the ZXING core classes that can also be used in B4J as none of those classes depend on android classes.
 
Upvote 0
Solution

LGS

Member
Licensed User
Longtime User
Hello Mr Johan.
Ok, understood.
I will have to do independent development for B4J.
Thanks for your support.
 
Upvote 0

LGS

Member
Licensed User
Longtime User
Mr. Johan.
Following one of your tutorials I was able to create the barcode (EAN13) as I had developed it in B4A.
However I still haven't been able to find the module for (EAN14), which I also need to recreate in B4J.

I would really appreciate if you can help me or direct me to find this module.

Thanks in advance for your customary support. 🤝
 
Upvote 0

LGS

Member
Licensed User
Longtime User
B4J - EAN13
1680303560506.png
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Your can try this for EAN 13 and ITF 14

 
Last edited:
Upvote 0

LGS

Member
Licensed User
Longtime User
Thank you very much Mr. Johan.
As always, his support is already customary.
The community is very lucky to have people like you, willing to help at all times.
It works like a charm 👍

Blessings 🙏
 
Upvote 0
Top