Android Question Options Dialog of PreferencesDialog v1.74

aeric

Expert
Licensed User
Longtime User
Dim btnOk As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Positive)
There is a bug in B4A when clicking on the options, the Dialog which has no OK button, caused an error. This error is not occurred in B4J.

The error is:
(Exception) java.lang.Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Index time: 2 ms (2 Items)
Error occurred on line: 214 (B4XDialog)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
at b4a.preferencesdialog.example.b4xdialog._getbutton(b4xdialog.java:135)
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.keywords.Common.CallSub4(Common.java:1082)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1037)
at b4a.preferencesdialog.example.preferencesdialog._raisebeforedialogdisplayed(preferencesdialog.java:3084)
at b4a.preferencesdialog.example.preferencesdialog$ResumableSub_ShowDialog.resume(preferencesdialog.java:818)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
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.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1770)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
For now, I am using Try-Catch to suppress the error.

B4X:
Private Sub PrefDialog1_BeforeDialogDisplayed (Template As Object)
    Try
        Dim btnCancel As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Cancel)
        btnCancel.Width = btnCancel.Width + 20dip
        btnCancel.Left = btnCancel.Left - 20dip
        btnCancel.TextColor = xui.Color_Red
        Dim btnOk As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Positive)
        If btnOk.IsInitialized Then
            btnOk.Width = btnOk.Width + 20dip
            btnOk.Left = btnCancel.Left - btnOk.Width
        End If
    Catch
        Log(LastException)
    End Try
End Sub
 

Attachments

  • PreferencesDialog.zip
    16 KB · Views: 207
Solution
This is actually the behavior of B4XDialog.
You can check the template type:
B4X:
Private Sub p_BeforeDialogDisplayed (Template As Object)
    Dim btnCancel As B4XView = p.Dialog.GetButton(xui.DialogResponse_Cancel)
    btnCancel.Width = btnCancel.Width + 60dip
    btnCancel.Left = btnCancel.Left - 60dip
    btnCancel.TextColor = xui.Color_Red
    If Template <> p.SearchTemplate And Template <> p.DateTemplate Then
        Dim btnOk As B4XView = p.Dialog.GetButton(xui.DialogResponse_Positive)
        btnOk.Width = btnOk.Width + 20dip
        btnOk.Left = btnCancel.Left - btnOk.Width
    End If
End Sub

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is actually the behavior of B4XDialog.
You can check the template type:
B4X:
Private Sub p_BeforeDialogDisplayed (Template As Object)
    Dim btnCancel As B4XView = p.Dialog.GetButton(xui.DialogResponse_Cancel)
    btnCancel.Width = btnCancel.Width + 60dip
    btnCancel.Left = btnCancel.Left - 60dip
    btnCancel.TextColor = xui.Color_Red
    If Template <> p.SearchTemplate And Template <> p.DateTemplate Then
        Dim btnOk As B4XView = p.Dialog.GetButton(xui.DialogResponse_Positive)
        btnOk.Width = btnOk.Width + 20dip
        btnOk.Left = btnCancel.Left - btnOk.Width
    End If
End Sub
 
Upvote 0
Solution
Top