B4J Question [SOLVED] LCD on Raspberry with custom character

Fabrice La

Active Member
Licensed User
Longtime User
Hi,
I am using this code
B4X:
Dim charE(8) As Byte
    charE = Array As Byte (0x00, 0x04, 0x0A, 0x0E, 0x11, 0x1F, 0x10, 0x0E) 'ê
    lcd.RunMethod("lcdPuts", Array(handle, "Pr t"))
    lcd.RunMethod("lcdPosition", Array(handle, 2,1))
    lcd.RunMethod("lcdChar", Array(handle, charE(8)))

and the error is :

B4X:
java.lang.ArrayIndexOutOfBoundsException
    at java.lang.reflect.Array.get(Native Method)
    at anywheresoftware.b4a.shell.ArraysUtils.getElement(ArraysUtils.java:76)
    at anywheresoftware.b4a.shell.Shell.getArrayElement(Shell.java:470)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:263)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    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.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at b4j.example.main.main(main.java:29)
Une erreur s'est produite en ligne: 78
java.lang.NullPointerException
    at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:360)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:172)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    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.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA$2.run(BA.java:229)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:114)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:146)
    at anywheresoftware.b4a.shell.Shel
l.raiseEventImpl(Shell.java:303)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    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)
 

DonManfred

Expert
Licensed User
Longtime User
java.lang.ArrayIndexOutOfBoundsException

Dim charE(8) As Byte
charE =
Array As Byte (0x00, 0x04, 0x0A, 0x0E, 0x11, 0x1F, 0x10, 0x0E)
lcd.RunMethod("lcdPuts", Array(handle, "Pr t"))
lcd.RunMethod(
"lcdPosition", Array(handle, 2,1))
lcd.RunMethod(
"lcdChar", Array(handle, charE(8)))

charE has 8 entries. 0 to 7!! But you are trying to access index 8 (outofbounds)
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
I did some modification and now other problem :

B4X:
    Dim charname1(8) As Byte 'é
    charname1 = Array As Byte (0x00, 0x02, 0x04, 0x0E, 0x11, 0x1F, 0x10, 0x0E)
    lcd.RunMethod("lcdCharDef", Array(handle, 1, charname1))
    lcd.RunMethod("lcdClear", Array(handle))
    lcd.RunMethod("lcdPosition", Array(handle, 0,0))
    lcd.RunMethod("lcdPuts", Array(handle, "Termin"))
    lcd.RunMethod("lcdPosition", Array(handle, 6,0))
    lcd.RunMethod("lcdPutchar", Array(handle, 1))

With this error :

B4X:
main._appstart (java line: 174)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Method: lcdPutchar not matched.
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:489)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:460)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:534)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:146)
    at b4j.example.main._appstart(main.java:174)
    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.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at b4j.exa
mple.main.main(main.java:29)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Method: lcdPutchar not matched.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:480)
    ... 13 more
Caused by: java.lang.RuntimeException: Method: lcdPutchar not matched.
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:129)
    at b4j.example.main$ResumableSub_finXML.resume(main.java:609)
    at b4j.example.main._finxml(main.java:352)
    at b4j.example.main._astream_newtext(main.java:216)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    ... 14 more
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Not good:
B4X:
Dim charname1(8) As Byte 'é
charname1 = Array As Byte (0x00, 0x02, 0x04, 0x0E, 0x11, 0x1F, 0x10, 0x0E)
Good:
B4X:
Dim charname1() As Byte = Array As Byte (0x00, 0x02, 0x04, 0x0E, 0x11, 0x1F, 0x10, 0x0E)

Where does this code come from?

Based on the error message you are not calling the correct method.
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
This line is probably sending an int instead of a byte - hence the method not matched error
B4X:
 lcd.RunMethod("lcdPutchar", Array(handle, 1))

You could try
B4X:
dim bytecode as byte = 0x01
...
 lcd.RunMethod("lcdPutchar", Array(handle, bytecode))
...
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
I try also this :

B4X:
Dim charname1() As Byte = Array As Byte (0x00, 0x02, 0x04, 0x0E, 0x11, 0x1F, 0x10, 0x0E)
lcd.RunMethod("lcdCharDef", Array(handle, 1, charname1))
lcd.RunMethod("lcdClear", Array(handle))
lcd.RunMethod("lcdPosition", Array(handle, 0,0))
lcd.RunMethod("lcdPuts", Array(handle, "Termin"))
lcd.RunMethod("lcdPosition", Array(handle, 6,0))
lcd.RunMethod("lcdPutchar", Array(handle, charname1))

Same problem
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
It only wants a single byte in lcdPutchar- you gave it an array of bytes (charname1).
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
Thanks Daestrum the solution is :

B4X:
Dim charname1() As Byte = Array As Byte (0x00, 0x02, 0x04, 0x0E, 0x11, 0x1F, 0x10, 0x0E)
Dim charname2() As Byte = Array As Byte (0x08, 0x14, 0x08, 0x00, 0x03, 0x04, 0x04, 0x03)
'Define the charactere in lcd
lcd.RunMethod("lcdCharDef", Array(handle, 1, charname1))
lcd.RunMethod("lcdCharDef", Array(handle, 2, charname2))
'the byte correspond to the integer you use to define the character
Dim bytecode1 As Byte = 0x01 ' for 1
Dim bytecode2 As Byte = 0x02 ' for 2

lcd.RunMethod("lcdClear", Array(handle))
lcd.RunMethod("lcdPosition", Array(handle, 0,0))
lcd.RunMethod("lcdPuts", Array(handle, "Termin"))
lcd.RunMethod("lcdPosition", Array(handle, 6,0)) 'place of the first character
lcd.RunMethod("lcdPutchar", Array(handle, bytecode1)) 'the first character is printed
lcd.RunMethod("lcdPosition", Array(handle, 7,0)) 'place of the second character
lcd.RunMethod("lcdPutchar", Array(handle, bytecode2))'the second character is printed

Problem solved
 
Last edited:
Upvote 0
Top