Android Question B4XInputTemplate crashes if setting Passwordmode True

CaStar

Member
Licensed User
Longtime User
Mysterious problem with Passwordmode (B4A 11.50).
If setting Passwordmode to True for B4XInputtemplate like this:

DialogInput.Initialize
Dim et As EditText = DialogInput.TextField1
et.PasswordMode = True
et.TextColor = xui.Color_Yellow
et.Gravity = Gravity.CENTER_HORIZONTAL


the application crashes showing this message:
1658914551913.png


Using this lines of code (Passwordmode commented out):

DialogInput.Initialize
Dim et As EditText = DialogInput.TextField1

' et.PasswordMode = True
et.TextColor = xui.Color_Yellow
et.Gravity = Gravity.CENTER_HORIZONTAL


it works.

How can I use Passwordmode True without crashing my APP?
 
Last edited:

CaStar

Member
Licensed User
Longtime User
Yes, there was a missing service start because of this is an old Application. But the password problem remains existing.

I wrote a test application with two buttons. Button 1 = "Enter text", Button 2 = "Enter password". Using Button 1 first, everything works fine. Using Button 2 first the app crashes.

This is the crash log:
B4X:
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 95 (B4XInputTemplate)
java.lang.RuntimeException: Class instance was not initialized (b4xdialog)
    at anywheresoftware.b4a.debug.Debug.shouldDelegate(Debug.java:242)
    at b4a.example.b4xdialog._setbuttonstate(b4xdialog.java:775)
    at b4a.example.b4xinputtemplate._validate(b4xinputtemplate.java:377)
    at b4a.example.b4xinputtemplate._textfield1_textchanged(b4xinputtemplate.java:423)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.objects.EditTextWrapper$1.afterTextChanged(EditTextWrapper.java:83)
    at android.widget.TextView.sendAfterTextChanged(TextView.java:10991)
    at android.widget.TextView.setText(TextView.java:6431)
    at android.widget.TextView.setText(TextView.java:6231)
    at android.widget.EditText.setText(EditText.java:146)
    at android.widget.TextView.setText(TextView.java:6188)
    at android.widget.TextView.setTransformationMethod(TextView.java:2814)
    at anywheresoftware.b4a.objects.EditTextWrapper.setPasswordMode(EditTextWrapper.java:147)
    at b4a.example.main$ResumableSub_EnterText.resume(main.java:501)
    at b4a.example.main._entertext(main.java:443)
    at b4a.example.main._button2_click(main.java:578)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7357)
    at android.widget.TextView.performClick(TextView.java:14263)
    at android.view.View.performClickInternal(View.java:7323)
    at android.view.View.access$3200(View.java:849)
    at android.view.View$PerformClick.run(View.java:27895)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:216)
    at android.app.ActivityThread.main(ActivityThread.java:7266)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

Ths is the B4A-Code:
B4X:
#Region  Project Attributes 
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim xui As XUI

    Dim Dlg As B4XDialog
    Dim DlgInput As B4XInputTemplate
    
    Private LAB_EnteredText As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    Dlg.Initialize(Activity)
    DlgInput.Initialize
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    EnterText(False)
End Sub

Private Sub Button2_Click
    EnterText(True)
End Sub

Private Sub EnterText(PasswordMode As Boolean)
    
    LAB_EnteredText.Text = ""
    
    Dim et As EditText = DlgInput.TextField1
    
    et.TextColor = xui.Color_Cyan
    et.Gravity = Gravity.CENTER_HORIZONTAL
    
    If PasswordMode Then
        DlgInput.lblTitle.Text = "Enter password:"
        et.PasswordMode = True
    Else
        DlgInput.lblTitle.Text = "Enter text:"
        '' et.PasswordMode = True ' Comented out because of "First time crash"
    End If
    
    Dlg.Title = "Dialogtest"
    Dlg.TitleBarColor = xui.Color_Blue
    Dlg.TitleBarTextColor = xui.Color_Yellow
    Dlg.ButtonsTextColor = Colors.RGB(50,205,50)
    
    Wait For (Dlg.ShowTemplate(DlgInput, "OK", "", "CANCEL")) Complete (Result As Int)
    
    If Result = xui.DialogResponse_Cancel Then Return
    
    LAB_EnteredText.Text =  DlgInput.text
End Sub
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
I built a test B4xpage app and everything works as expected without the problem you described.

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dialog.Initialize(Root)
    inputTemlate.Initialize
    Dim et As EditText = inputTemlate.TextField1
    et.PasswordMode = True
    
    et.TextColor = xui.Color_Yellow
    et.Gravity = Gravity.CENTER_HORIZONTAL
    
    Wait For(Dialog.ShowTemplate(inputTemlate, "Yes", "No", ""))complete(intResult As Int)
    If intResult<>xui.DialogResponse_Positive Then
        Return
    End If
    
    Log(inputTemlate.Text)
End Sub
 

Attachments

  • Project.zip
    14.6 KB · Views: 32
Upvote 0
Top