Android Question Why does this code stop when run from a class?

Discussion in 'Android Questions' started by RB Smissaert, Dec 8, 2018.

Thread Status:
Not open for further replies.
  1. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Code:
    Public Sub InputBox2(strPrompt As String, _
         strTitle 
    As String, _
         strHint 
    As String, _
         strDefault 
    As String, _
         iTitleFontSize 
    As Int, _
         iTitleFontColour 
    As Int, _
           iPromptColour 
    As Int, _
         iHintColour 
    As Int, _
         iInputColour 
    As Int, _
           csPrompt 
    As CSBuilder, _
           bmpIcon 
    As Bitmap, _
           bCancelable 
    As Boolean, _
         iPromptHeight 
    As Int, _
         bHidePassword 
    As Boolean) As ResumableSub
         
     
    Dim csPrompt As CSBuilder
     
    Dim csTitle As CSBuilder
     
    Dim oJava As JavaObject
     
     mbHidePassword = bHidePassword
     
     
    If iTitleFontColour = 0 Then
      iTitleFontColour = 
    Colors.RGB(000)
     
    End If
     
     
    If iPromptColour = 0 Then
      iPromptColour = 
    Colors.RGB(000)
     
    End If
     
     
    If iHintColour = 0 Then
      iHintColour = 
    Colors.RGB(000)
     
    End If
     
     
    If iInputColour = 0 Then
      iInputColour = 
    Colors.RGB(000)
     
    End If
     
     
    If csPrompt.IsInitialized = False Then
      csPrompt.Initialize.Size(
    16).Color(iPromptColour).Append(strPrompt).PopAll
     
    End If
     
     csTitle.Initialize.Typeface(
    Typeface.DEFAULT).Size(iTitleFontSize).Color(iTitleFontColour).Append(strTitle).PopAll
     
     
    'note here that the OK and Cancel have been swapped!!
     '----------------------------------------------------
     oJava = Input_Dialog.ShowAsync(csTitle, "Cancel""OK""", bmpIcon, bCancelable)
     oJava.RunMethod(
    "setTitle"Array(csTitle))
     
     
    Wait For (oJava) Dialog_Ready(pnl As Panel'>>>>>> code stops here!
     pnl.LoadLayout("Input_Dialog")
     
     fledtInputbox.Hint = strHint
     fledtInputbox.EditText.TextColor = iInputColour
     fledtInputbox.EditText.HintColor = iHintColour
     
     
    'as we have the hint, no prompt label may be needed
     If strPrompt.Length > 0 Then
      
    If iPromptHeight = -1 Then
       lblInputBox.Height = sUtils.MeasureMultilineTextHeight(lblInputBox, csPrompt) + 
    20dip
      
    Else
       
    'not sure we need this option, MeasureMultilineTextHeight seems to work well
       lblInputBox.Height = iPromptHeight
      
    End If
      General.RunLog(
    "InputBox2, lblInputBox.Height: " & lblInputBox.Height)
      Input_Dialog.SetSize(
    96%x, lblInputBox.Height  + 200dip)
      lblInputBox.Text = csPrompt
     
    Else
      Input_Dialog.SetSize(
    96%x200dip)
      lblInputBox.Visible = 
    False
     
    End If
     
     
    If strDefault.Length > 0 Then
      fledtInputbox.Text = strDefault
     
    End If
     
     
    Wait For (oJava) Dialog_Result(res As Int)
     
     
    'note here that the OK and Cancel have been swapped!!
     '----------------------------------------------------
     If res = DialogResponse.CANCEL Then
      
    Return fledtInputbox.text 'OK button
     Else
      
    Return "" 'Cancel button
     End If
     
    End Sub
    This code is in a class module and it all runs fine when I run it from main.
    However when I run it from a another class the above code just stops at the indicated line.

    This is the Sub in that other class:

    Code:
    Public Sub Connect2DB(strDatabase As String, strPrompt As StringAs ResumableSub
     
     
    Dim strResult As String
     
    Dim bCreate As Boolean
     
     bCreate = 
    File.Exists(Starter.strAppDir, strDatabase) = False
     
     
    If strDatabase = "PhonePatsE.db" Then
      bEncryptedDB = 
    True
      
    If strPW.Length = 0 Then
       
       
    Wait For(cEvents.InputBox2(strPrompt, _
        
    "Connect to database""""", _
        
    180000Null, General.bmpIcon32, True, -1, bHidePassword)) _
        Complete (strResult 
    As String)
    Any idea what the problem is here?
    I also tried with the above Sub with no return value, but same problem.

    RBS
     
  2. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    This has not to do with calling it from a class, but I think with the fact that I am calling this too early in the startup sequence of the app.
    Not sure yet what is missing to make it fail.

    RBS
     
  3. Brandsum

    Brandsum Active Member Licensed User

    Did you Initialized the class instance cEvents before calling cEvents.InputBox2 ?

    Can you post the error log here?
     
  4. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Yes, I did.
    There is no error
    Yes, cEvents was initialized and part of the Sub InputBox2 in it runs.
    There is no error in the unfiltered log. I tried with un-ticking log filter but couldn't get a clear error message then either.
    I have copied the unfiltered log and will attach the dump, but not sure it shows anything relevant.

    RBS
     

    Attached Files:

  5. Brandsum

    Brandsum Active Member Licensed User

    Which library are you using for Input_Dialog?
    This one? https://www.b4x.com/android/forum/threads/dialogs-library.6776/

    I have tested your code. It works fine. Assuming you are using the above lib here is the code:
    Code:
    'Class Test1

    Sub Class_Globals
        
    Dim Input_Dialog As CustomLayoutDialog
    End Sub

    Public Sub Initialize

    End Sub

    Public Sub InputBox2() As ResumableSub
      
        
    Dim oJava As JavaObject 
        oJava = Input_Dialog.ShowAsync(
    "Hi""Cancel""OK"""NullTrue)
     
        
    Wait For (oJava) Dialog_Ready(pnl As Panel'>>>>>> code stoped here for you! but works for me!
        pnl.Color = Colors.Red 'just changed the color cause I dont have the layout file
     
        
    Wait For (oJava) Dialog_Result(res As Int)
     
        
    If res = DialogResponse.CANCEL Then
            
    Return "ok"
        
    Else
            
    Return "" 'Cancel button
        End If
     
    End Sub
    Code:
    'Class Test2

    Sub Class_Globals
        
    Dim text1_class As Test1
    End Sub

    Public Sub Initialize
        text1_class.Initialize
    End Sub

    Public Sub callInputBox2() As ResumableSub
        
    wait for (text1_class.InputBox2) Complete (strResult As String)
        
    Return strResult
    End Sub
    Here is the Activity code from which I am calling class Test2 and then Test2 is calling Test1:
    Code:
    Dim test2_class As test2
    test2_class.Initialize
    wait for (test2_class.callInputBox2) Complete (strResult As String)
    Log(strResult)
     
    Last edited: Dec 9, 2018
  6. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Yes, I am using the same library, Dialogs 4.01, got it from here:
    https://www.b4x.com/android/forum/t...-dialogs-and-async-methods.80204/#post-507930
    My Inputbox2 is an adaption from one of Erel's examples in the above thread.

    It works fine for me as well and I use that code in many places. For some reason it just fails when I call it early in the app
    startup sequence, to connect to SQLite. Problem is I can't see any error.

    RBS
     
  7. Brandsum

    Brandsum Active Member Licensed User

    Are you calling it from Starter service?
     
  8. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    No, it starts from Main - Activity_Create that calls the Sub to connect to the DB:

    cConnection.Connect2DB(cConnection.strDB, "Type in the password to connect.")

    cConnection is my SQLite connection class.

    Then Connect2DB calls Inputbox2, which is in a different class:

    Wait For(cEvents.InputBox2(strPrompt, _
    "Connect to database", "", "", _
    18, 0, 0, 0, 0, Null, General.bmpIcon32, True, -1, bHidePassword)) _
    Complete (strResult As String)

    RBS
     
  9. Brandsum

    Brandsum Active Member Licensed User

    Don't know what is happening to your end. If you can upload your project then I can give a try.
     
  10. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    I made a small demo project, which as far as I can see does exactly the same as the project where InputBox2 doesn't work.
    Unfortunately this demo project works fine, so I get the input dialog.
    I stepped with the debugger through both projects and can't see any difference, so I have no idea what the problem is in the real project.
    The manifests of both projects are the same as well.
    Although I can't demonstrate the problem I attached the demo project.
    Any ideas what could be the problem here?

    RBS
     

    Attached Files:

  11. Erel

    Erel Administrator Staff Member Licensed User

  12. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Thanks, will do that.
    I wasn't that happy in any case with all that Java stuff in my InputBox2 routine as one can't be sure
    really what is going on if you don't know Java.

    RBS
     
  13. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    As the EditText is declared as B4XView how do I set PasswordMode?

    Is there some Java code to handle that?

    RBS
     
  14. LucaMs

    LucaMs Expert Licensed User

     
  15. Erel

    Erel Administrator Staff Member Licensed User

    You should start a new thread for this.
    Code:
    Dim et As EditText = TheB4XView
    et.PasswordMode = 
    True
     
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice