B4J Question [SOLVED]lanterna

a.consorti

Member
Licensed User
Good morning,
regarding the code for writing TUI interfaces already started in a previous post (https://www.b4x.com/android/forum/threads/solved-lanterna.161843/#post-992685)
I'm trying to understand how to call a modal window that accepts the classic "YES" and "No" to understand how to proceed.

I tried adding this sub to the code:

Code:
Sub ShowMessageDialog(title As String, message As String)
    ' Inizializza MessageDialogButton staticamente
    Dim MessageDialogButton As JavaObject
    MessageDialogButton.InitializeStatic("com.googlecode.lanterna.gui2.dialogs.MessageDialogButton")
   
    ' Ottiene il pulsante OK staticamente
    Dim buttonOK As Object = MessageDialogButton.GetField("OK")
   
    ' Inizializza MessageDialog e chiama il metodo showMessageDialog
    Dim MessageDialog As JavaObject
    MessageDialog.InitializeStatic("com.googlecode.lanterna.gui2.dialogs.MessageDialog")
   
    ' Esegui il metodo showMessageDialog con i parametri corretti
    MessageDialog.RunMethod("showMessageDialog", Array As Object(gui, title, message, Array As Object(buttonOK)))
End Sub

and then recall it via:

code2:
ShowMessageDialog("WARNING", "Operazione non rilevata!")

Unfortunately I always get the following response:

Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Method: showMessageDialog not matched.

Can you give me some suggestions?
 
Solution

The problem is the Array As Object(buttonOK), you need to pass an array of the correct type using JavaObject InitializeArray.
B4X:
Sub ShowMessageDialog(title As String, message As String)
    ' Inizializza MessageDialogButton staticamente
    Dim MessageDialogButton As JavaObject
    MessageDialogButton.InitializeStatic("com.googlecode.lanterna.gui2.dialogs.MessageDialogButton")
 
    ' Ottiene il pulsante OK staticamente
    Dim buttonOK As Object = MessageDialogButton.GetField("OK")
 
    ' Inizializza MessageDialog e chiama il metodo...

teddybear

Well-Known Member
Licensed User

The problem is the Array As Object(buttonOK), you need to pass an array of the correct type using JavaObject InitializeArray.
B4X:
Sub ShowMessageDialog(title As String, message As String)
    ' Inizializza MessageDialogButton staticamente
    Dim MessageDialogButton As JavaObject
    MessageDialogButton.InitializeStatic("com.googlecode.lanterna.gui2.dialogs.MessageDialogButton")
 
    ' Ottiene il pulsante OK staticamente
    Dim buttonOK As Object = MessageDialogButton.GetField("OK")
 
    ' Inizializza MessageDialog e chiama il metodo showMessageDialog
    Dim MessageDialog As JavaObject
    MessageDialog.InitializeStatic("com.googlecode.lanterna.gui2.dialogs.MessageDialog")
    Dim jo As JavaObject
    ' Esegui il metodo showMessageDialog con i parametri corretti
    MessageDialog.RunMethod("showMessageDialog", Array As Object(gui, title, message, jo.InitializeArray("com.googlecode.lanterna.gui2.dialogs.MessageDialogButton",Array(buttonOK))))
End Sub
 
Upvote 1
Solution

a.consorti

Member
Licensed User
Thank you very much. It works!!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…