Android Question Error : B4XDialog - java.lang.NullPointerException: Attempt to invoke virtual method 'anywheresoftware.b4a.BA$IterableList anywheresoftware.b4a.object

hi,
I Use B4A.
I Attached Image Of The Libraries I use In My Project .
I face error in B4XDialog Library In Release Mode only, But in Debug Mode Work Very Good .
When I Answer Yes , The App Exit And Show This Error (In Release Mode):
The Error ::
b4xdialog_getbutton (java line: 336)
java.lang.NullPointerException: Attempt to invoke virtual method 'anywheresoftware.b4a.BA$IterableList anywheresoftware.b4a.objects.B4XViewWrapper.GetAllViewsRecursive()' on a null object reference
    at b4a.example.b4xdialog._getbutton(b4xdialog.java:336)
    at b4a.example.b4xdialog._setbuttonstate(b4xdialog.java:461)
    at b4a.example.b4xinputtemplate._validate(b4xinputtemplate.java:272)
    at b4a.example.b4xinputtemplate._textfield1_textchanged(b4xinputtemplate.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.objects.EditTextWrapper$1.afterTextChanged(EditTextWrapper.java:83)
    at android.widget.TextView.sendAfterTextChanged(TextView.java:11919)
    at android.widget.TextView.setText(TextView.java:7022)
    at android.widget.TextView.setText(TextView.java:6801)
    at android.widget.EditText.setText(EditText.java:140)
    at android.widget.TextView.setText(TextView.java:6753)
    at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:39)
    at anywheresoftware.b4a.objects.B4XViewWrapper.setText(B4XViewWrapper.java:229)
    at b4a.example.cart$ResumableSub_Add_Item_To_Cart_By_Barcode_Btn1_Click.resume(cart.java:616)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.keywords.Common$1.onClick(Common.java:490)
    at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:188)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8663)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)


My Code is ::
If Main.SQL1.ExecQuerySingleResult("SELECT COUNT('Item_Name') FROM Cart WHERE Item_Barcode='" & Barcode_TXT & "'") > 0 Then
                'ToastMessageShow("Item Exist in Cart",False)
                'Msgbox2Async("The item is in the cart Do you want to modify the quantity?", Barcode_TXT, "Yes", "", "No", Null, False)
        
                Msgbox2Async("The item is already in the cart Do you want to modify the quantity?", Barcode_TXT, "Yes", "", "No", Null, False)
                Wait For Msgbox_Result (Result As Int)
                If Result = DialogResponse.POSITIVE Then
                
                    'The Error Start From Here
                    Dim xui2 As XUI
                    Dim dialog2 As B4XDialog
            
                    If dialog2.IsInitialized = False Then
                        dialog2.Initialize(Activity)
                    End If
                
                    Dim input As B4XInputTemplate
                
                    If input.IsInitialized = False Then
                        input.Initialize
                    End If
                
                    input.lblTitle.Text = "Enter the required quantity:"
                    input.lblTitle.SetTextAlignment("CENTER","RIGHT")
                    input.TextField1.Text=Main.SQL1.ExecQuerySingleResult("SELECT QTY FROM Cart WHERE Item_Barcode='" & Barcode_TXT & "'")
                    input.ConfigureForNumbers(False, False) 'AllowDecimals, AllowNegative
                
                    'Wait For (dialog2.ShowTemplate(input, "OK", "", "Cancel")) Complete (Result2 As Int)
                    Dim rs2 As ResumableSub = dialog2.ShowTemplate(input, "OK", "", "CANCEL")
                    'thewifidialog.GetButton(xui.DialogResponse_Positive).Enabled = False
                    Wait For (rs2) Complete (Result2 As Int)
                
                    If Result2 = xui2.DialogResponse_Positive Then
                        Dim res2 As Int = input.Text 'no need to check with IsNumber
                        'Log(res)
                
                        Main.SQL1.ExecNonQuery("UPDATE Cart SET QTY='" & res2 & "' WHERE Item_Barcode='" & Barcode_TXT & "'")
                        Load_Cart_Data
                
                    End If
                
                End If
        
            Else
        
                Dim QTY_Dialog As InputDialog
                QTY_Dialog.Input = 1
                QTY_Dialog.InputType = QTY_Dialog.INPUT_TYPE_INTEGER
    
                Dim sf As Object = QTY_Dialog.ShowAsync("", "QTY", "OK", "", "Cancel", Null, False)
                Wait For (sf) Dialog_Result(Result As Int)
                If Result = DialogResponse.POSITIVE Then
                    'Log(QTY_Dialog.Input)
                    If QTY_Dialog.Input > 0 Then
                        Module1.Insert_Into_Cart(QTY_Dialog.Input,Barcode_TXT)
                        Load_Cart_Data
                        'Sleep(0)
                        'Log(Cart_Items_CustomListView1.Size -1)
                        'ToastMessageShow(CustomListView1.Size -1,False)
            
                    Else
                        Msgbox("The quantity must be greater than zero",True)
                    End If
                End If
            End If
 

Attachments

  • Libraries.png
    Libraries.png
    11.6 KB · Views: 95
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
You don't need to check whether IsInitialized is false. It will always be false after you call dim.

Try it with this code:
B4X:
                    Dim rs2 As ResumableSub = dialog2.ShowTemplate(input, "OK", "", "CANCEL")
                   input.lblTitle.Text = "Enter the required quantity:"
                    input.lblTitle.SetTextAlignment("CENTER","RIGHT")
                    input.TextField1.Text=Main.SQL1.ExecQuerySingleResult("SELECT QTY FROM Cart WHERE Item_Barcode='" & Barcode_TXT & "'")
                    input.ConfigureForNumbers(False, False) 'AllowDecimals, AllowNegative
                  Wait For (rs2) Complete (Result2 As Int)
 
Upvote 0
You don't need to check whether IsInitialized is false. It will always be false after you call dim.

Try it with this code:
B4X:
                    Dim rs2 As ResumableSub = dialog2.ShowTemplate(input, "OK", "", "CANCEL")
                   input.lblTitle.Text = "Enter the required quantity:"
                    input.lblTitle.SetTextAlignment("CENTER","RIGHT")
                    input.TextField1.Text=Main.SQL1.ExecQuerySingleResult("SELECT QTY FROM Cart WHERE Item_Barcode='" & Barcode_TXT & "'")
                    input.ConfigureForNumbers(False, False) 'AllowDecimals, AllowNegative
                  Wait For (rs2) Complete (Result2 As Int)
Thanks .. I will Try
 
Upvote 0
Top