B4J Question Problem sending image in file from B4J to B4A

HARRY

Active Member
Licensed User
Longtime User
I am trying to realize what is said in the title. The code in B4J is as follows:

B4X:
Dim bitmap As Image
    If File.Exists("/home/pi/MyApps/Domo/Images","Webcam" & ImageNr & ".jpg")  Then
        bitmap.Initialize("/home/pi/MyApps/Domo/Images","Webcam" & ImageNr & ".jpg")
        Dim dataToSend() As Byte = ser.ConvertObjectToBytes(CreateMap("FileName": "Webcam", "Data": bitmap))
        Stream3.Write(dataToSend)
    Else
        Stream2.Write("-4"& CRLF)
    End If

I get an error on bitmap.initialize. The message starts with:

Error occurred on line: 322 (Main) 'which is bitmap.Initialize
java.lang.RuntimeException: java.lang.NoClassDefFoundError: javafx/scene/image/Image
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA$3.run(BA.java:178)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:111)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:131)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:300)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
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:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.jav
a:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
Caused by: java.lang.NoClassDefFoundError: javafx/scene/image/Image
at anywheresoftware.b4j.objects.ImageViewWrapper$ImageWrapper.Initialize2(ImageViewWrapper.java:125)
at anywheresoftware.b4j.objects.ImageViewWrapper$ImageWrapper.Initialize(ImageViewWrapper.java:118)
at b4j.example.main._sendfile(main.java:545)
at b4j.example.main._webcam_processcompleted(main.java:991)
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:497) a.s.o


What am I doing wrong?

The code in b4A is:
B4X:
Sub Stream3_NewData(data() As Byte)
    Dim image() As Byte= ser.ConvertBytesToObject(data)
    'convert the array of bytes to image
    Dim in As InputStream
    in.InitializeFromBytesArray(image, 0,image.length)   
    bmpPhoto.Initialize2(in)    'bmpPhoto is an activity global
    'draw the image
    StartActivity(Webcam)   ín this activity the bitmap is drawn
End Sub

Perhaps somebody can check this code as well ; it may prevent another thread.

Regards

Harry
 

Daestrum

Expert
Licensed User
Longtime User
Looking at the error message - NoClassDefFoundError - is this a non ui application?
If so then it will not know what a javafx image is as javafx is not included in a non-ui application.
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
Thanks Erel,

Sending now works. The next problem is receiving in B4A. The current code is:
B4X:
Sub Stream3_NewData(data() As Byte)
    Dim thisimage As Bitmap = ser.ConvertBytesToObject(data())
    Dim in As InputStream
    in.InitializeFromBytesArray(thisimage, 0,thisimage.length)
    bmpPhoto.Initialize2(in)   'bmpPhoto is a global object.
    'draw the image
    StartActivity(Webcam)     'in this activity the display occurs
End Sub

Several erors are reported; apparently I am doing it totally wrong!
Missing parameter on line Dim thisimage etc
Cannot cast type(Type=String,Rank=0,RemoteObject=true) to (t ype=Byte, Rank=1, RemoteObject=true) on in.initialize

Please, again some help.

Harry
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
Sorry Erel,

But I still get an error reported in B4A as follows:

at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Error occurred on line: 264 (Main)
java.lang.NullPointerException
at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:461)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:283)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)

Line 264 reads:

Dim m As Map = ser.ConvertBytesToObject(data)

The whole sub now reads:
B4X:
Sub Stream3_NewData(data() As Byte)
    Dim m As Map = ser.ConvertBytesToObject(data)
    Log(m.Get("FileName"))
    Dim bmpData() As Byte = m.Get("Data")
    Dim in As InputStream
    in.InitializeFromBytesArray(bmpData, 0,bmpData.length) 
    bmpPhoto.Initialize2(in)
    'draw the image
    StartActivity(Webcam)
End Sub

B4J reports the length of dataToSend as e.g. 93000
B4a reports the length of data at Stream3_NewData as e.g. 1448
The JPEG file size is some 96KB
The colour image = 960 * 720

Harry
 
Last edited:
Upvote 0
Top