B4J Question [Error?] java.lang.NegativeArraySizeException: -1

rtek1000

Active Member
Licensed User
Longtime User
Warning in the log.png


Waiting for debugger to connect...
Program started.
Serial1.Open
astream.Initialize

astream.Close
java.lang.NegativeArraySizeException: -1
at jssc.SerialNativeInterface.readBytes(Native Method)
at jssc.SerialPort.readBytes(SerialPort.java:437)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:165)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:157)
at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:216)
at java.base/java.lang.Thread.run(Thread.java:834)
Serial1.Close

This warning does not cause the application to stop.

But it fails to catch the error for treatment using try catch.

This warning appears when the astream is closed.

This warning appears even though the serial port is not receiving data or sending data.

B4X:
Log("astream.Close")
astream.Close
            
Sleep(1000)
            
Log("Serial1.Close")
Serial1.Close

It seems that this warning is not considered an error, so it is not caught with these subroutines:

B4X:
Sub AStream_Error
    Log("AStream_Error")
    Log(LastException)
End Sub

Sub AStream_Terminated
    Log("AStream_Terminated")
End Sub

Does anyone know how to prevent this error from appearing in the LOG?

Reference: [B4X] AsyncStreams Tutorial
Errors
The Error event will be raised if there is any error. You can use LastException to find the reason for the error. In most cases you will want to close the connection when an error occurs.
 

aminoacid

Active Member
Licensed User
Longtime User
View attachment 110031



This warning does not cause the application to stop.

But it fails to catch the error for treatment using try catch.

This warning appears when the astream is closed.

This warning appears even though the serial port is not receiving data or sending data.

B4X:
Log("astream.Close")
astream.Close
           
Sleep(1000)
           
Log("Serial1.Close")
Serial1.Close

It seems that this warning is not considered an error, so it is not caught with these subroutines:

B4X:
Sub AStream_Error
    Log("AStream_Error")
    Log(LastException)
End Sub

Sub AStream_Terminated
    Log("AStream_Terminated")
End Sub

Does anyone know how to prevent this error from appearing in the LOG?

Reference: [B4X] AsyncStreams Tutorial
Hi!
Did you find the cause of the Exception?
 
Upvote 0
I confirmed your exception result. I also confirmed it did not (seem to) make any difference. Unless you ran into any further problems with this issue I will ignore it as Erel says.
 
Upvote 0
Top