Android Question Debug Issue

bocker77

Active Member
Licensed User
Longtime User
I am getting the following error during a simple IF statement. This appears to have happened after installing a game on my PC. The game in question upgraded the Visual C++ run time environment which should not be causing my problem. I have no idea if it was the install of the game but that is the only thing that changed and that I can think of. Also I have rebooted my PC to clear memory but I still get this error. It also errors out in Release.

Java Version: 11 seen during compile.

Error occurred on line: 1130 (B4XMainPage)
java.lang.NullPointerException
at anywheresoftware.b4a.debug.RDebugUtils.equals(RDebugUtils.java:46)
at anywheresoftware.b4a.debug.RDebugUtils.solveBoolean(RDebugUtils.java:122)Also
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:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:250)
at android.app.ActivityThread.main(ActivityThread.java:7803)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)

Line 1130 is the IF statement
B4X:
    If 13 < 11 Then
        ' Determine if the Power's capital has been captured
        bCapitalCaptured = Int2Bool(sqlDB.ExecQuerySingleResult("SELECT captured FROM Powers " & _
                                                            "WHERE Power = " & Territory.OrigPWR))        
    End If
 

Daestrum

Expert
Licensed User
Longtime User
Was there any more to the error message, as usually theres a "Caused by ..." line which can give a good hint to the problem.

Also it's a runtime error, not a compile error.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
I know its a runtime error. It errors out when debugging on that line. The error message to me is pointing to Java since it indicates a line in the Java code (RDebugUtils.java:46). There is no line with what you mentioned. In my estimation the install of the game is what caused this problem. I plan on uninstalling the game but that may not help either. Hopefully if I go this route I can restore my system back before the install of the game.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
After further review now I realize that the error is on the phone not the PC just what Daestrum said. The problem is with my phone but what it is who know!
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Here is the log. I have a breakpoint before the crash and get there in Debug mode. It never got there before the crash in Release. Thanks for looking into this for me!

Logger connected to: motorola moto g power
--------- beginning of crash
FATAL EXCEPTION: main
Process: b4a.example, PID: 24953
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at b4a.example.b4xmainpage$ResumableSub_lsvTerritories_ItemClick.resume(b4xmainpage.java:4335)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:250)
at android.app.ActivityThread.main(ActivityThread.java:7803)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
--------- beginning of main
Not starting debugger since process cannot load the jdwp agent.
No Network Security Config specified, using platform default
No Network Security Config specified, using platform default
common created.
Starting remote logger. Port: 35352
*** Service (starter) Create ***
** Service (starter) Start **
QUALCOMM build : d4cfdf3, Ic907de5ed0
Build Date : 09/25/20
OpenGL ES Shader Compiler Version: EV031.32.02.01
Local Branch : mybrancheaff3d46-e51f-f136-8926-1458d0b52af0
Remote Branch : quic/gfx-adreno.lnx.1.0.r116-rel
Remote Branch : NONE
Reconstruct Branch : NOTHING
Build Config : S P 10.0.7 AArch64
Driver Path : /vendor/lib64/egl/libGLESv2_adreno.so
PFP: 0x016ee190, ME: 0x00000000
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
After accept
New Game
Sucessfully bound to com.google.android.tts
Connected to ComponentInfo{com.google.android.tts/com.google.android.apps.speech.tts.googletts.service.GoogleTtsService}
Set up connection to ComponentInfo{com.google.android.tts/com.google.android.apps.speech.tts.googletts.service.GoogleTtsService}
Skipped 32 frames! The application may be doing too much work on its main thread.
b4xmainpage$ResumableSub_lsvTerritories_ItemClickresume (java line: 4335)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at b4a.example.b4xmainpage$ResumableSub_lsvTerritories_ItemClick.resume(b4xmainpage.java:4335)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:250)
at android.app.ActivityThread.main(ActivityThread.java:7803)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
FATAL EXCEPTION: main
Process: b4a.example, PID: 25330
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at b4a.example.b4xmainpage$ResumableSub_lsvTerritories_ItemClick.resume(b4xmainpage.java:4335)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:250)
at android.app.ActivityThread.main(ActivityThread.java:7803)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
Sending signal. PID: 25330 SIG: 9
Not starting debugger since process cannot load the jdwp agent.
No Network Security Config specified, using platform default
No Network Security Config specified, using platform default
common created.
Starting remote logger. Port: 35352
*** Service (starter) Create ***
** Service (starter) Start **
QUALCOMM build : d4cfdf3, Ic907de5ed0
Build Date : 09/25/20
OpenGL ES Shader Compiler Version: EV031.32.02.01
Local Branch : mybrancheaff3d46-e51f-f136-8926-1458d0b52af0
Remote Branch : quic/gfx-adreno.lnx.1.0.r116-rel
Remote Branch : NONE
Reconstruct Branch : NOTHING
Build Config : S P 10.0.7 AArch64
Driver Path : /vendor/lib64/egl/libGLESv2_adreno.so
PFP: 0x016ee190, ME: 0x00000000
After accept
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
New Game
Sucessfully bound to com.google.android.tts
Connected to ComponentInfo{com.google.android.tts/com.google.android.apps.speech.tts.googletts.service.GoogleTtsService}
Set up connection to ComponentInfo{com.google.android.tts/com.google.android.apps.speech.tts.googletts.service.GoogleTtsService}
Skipped 32 frames! The application may be doing too much work on its main thread.
b4xmainpage$ResumableSub_lsvTerritories_ItemClickresume (java line: 4335)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at b4a.example.b4xmainpage$ResumableSub_lsvTerritories_ItemClick.resume(b4xmainpage.java:4335)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:250)
at android.app.ActivityThread.main(ActivityThread.java:7803)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
FATAL EXCEPTION: main
Process: b4a.example, PID: 25530
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at b4a.example.b4xmainpage$ResumableSub_lsvTerritories_ItemClick.resume(b4xmainpage.java:4335)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:250)
at android.app.ActivityThread.main(ActivityThread.java:7803)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
The error seems to be in this sub
B4X:
Sub_lsvTerritories_ItemClick
and maybe there is an incorrect IF statement to compare a String to a Null Object.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
What about Erels rule 5 of Erel's [B4X] "Code Smells" - common mistakes and other tips:
5. Not using parameterized queries::
'very bad
SQL.ExecNonQuery("INSERT INTO table1 VALUES ('" & EditText1.Text & "'") 
'ugly, will break if there is an apostrophe in the text and vulnerable to SQL injections.

'very good
SQL.ExecNonQuery2("INSERT INTO table1 VALUES (?)", Array(EditText1.Text))

Update: add missing good solution
 
Last edited:
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Sagenut, you are so correct that the error is in that sub. The only problem is that it crashes on a simple IF statement.

MicroDrie, the statement after the IF statement is an sql query that will error out because it is returning a NULL value. The original IF statement will not execute the sql unless there is a valid response back from the query.

So it looks like Erel is going to look over the Release log that I sent. He as you know is a busy man.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Can you post the sub?
Hiding sensible data if present.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Before mucking with the code it looked like this.

B4X:
'   Determine If the Power's capital has been captured
'   If Territory.OrigPWR >= Germany And Territory.OrigPWR <= France Then
    If 13 < 11 Then
            bCapitalCaptured = Int2Bool(sqlDB.ExecQuerySingleResult("SELECT captured FROM Powers " & _
                                                            "WHERE Power = " & Territory.OrigPWR))
    End If
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Can we known the declaration of 13 and 11?
String, Int, Object.......
And of bCapitalCaptured.....
We need more info, we can't guess.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Sagenut, here is the code. See if can find the problem. Also thanks for looking at it.

B4X:
' Power takes a territory
Private Sub lsvTerritories_ItemClick (Position As Int, Value As Object)    
    Dim iChgPWR As Int
    Dim strTerrType As String
    Dim Territory As typTerritory
    
    Territory = Value    
    strTerr = ""
    ' Player already occupies this territory
    If Territory.PWR = iPower Then
        Information(strPower & " player already occupies " & _
                Chr(34) & Territory.Name & Chr(34) & ".")    
        Return
    ' Player from the same side occupies this territory
    Else If GetPowersSide(Territory.PWR) = GetPowersSide(iPower) Then
        Information("A Power on your side already occupies " & _
                Chr(34) & Territory.Name & Chr(34) & ".")
        Return
    ' Japan is not at war with the UK
    Else If iPower = Japan And Territory.PWR = Dutch And Not(bJapUKAtWar) Then
        Information("Japan is not allowed to attack a Dutch territory unless it " & _
                    "is at war with the United Kingdom and ANZAC.")
        Return
    End If
    strTerrType = GetPowerName(Territory.PWR)
    ' Confirm that Power has taken control of this Territory
    csMsgText.Initialize.Typeface(fntMsgNormal).Append("Confirm that ").Bold.Color(HiLite).Append(strPower).Pop.Pop
    csMsgText.Append(" has taken control of ").Typeface(fntMsgItallic).Append(Territory.Name).pop
    If strTerrType <> "Error" Then
        csMsgText.Append(" from ").Bold.Color(HiLite).Append(strTerrType).Pop.Pop.Append(".").popall
    Else        
        csMsgText.Popall
    End If
    tmpLogText.Text = csMsgText
    tmpLogText.mBase.Height = 140dip
    MsgDlg.PutAtTop = True
    Dim rsp As ResumableSub = MsgDlg.ShowTemplate(tmpLogText, "Yes", "No", "")
    Dim btnYes As B4XView = MsgDlg.GetButton(xui.DialogResponse_Positive)
    btnYes.SetBitmap(bmpBtnUp)
    Dim btnNo As B4XView = MsgDlg.GetButton(xui.DialogResponse_Negative)
    btnNo.SetBitmap(bmpBtnUp)
    Wait For (rsp) Complete (Result As Int)
    ' If not Return
    If Result = xui.DialogResponse_Negative Then Return
    lstTerr.Add(Territory.Name)
    iChgPWR = iPower
'    If Territory.OrigPWR = Germany Then
'        If Territory.OrigPWR <= France Then
'            Determine If the Power's capital has been captured
    If 13 < 11 Then
            bCapitalCaptured = Int2Bool(sqlDB.ExecQuerySingleResult("SELECT captured FROM Powers " & _
                                                            "WHERE Power = " & Territory.OrigPWR))        
            
'            End If
    End If
    ' Capturing and Liberating Capitals
    If Territory.Capital = "Y" Then
        ' Capturing a Capital
        If GetPowersSide(iPower) <> GetPowersSide(Territory.PWR) And _
           Not(bCapitalCaptured) Then
            iIPCsCapital = 0
            ' Set Power to Captured
            sqlDB.ExecNonQuery("UPDATE Powers SET captured = 1 " & _
                               "WHERE power = " & Territory.PWR)
            ' Transfer all unspent IPCs from the treasury of the of the Power's captured capital
            iIPCsCapital = sqlDB.ExecQuerySingleResult("SELECT ipcs FROM Powers " & _
                                                       "WHERE power = " & Territory.PWR)
            sqlDB.ExecNonQuery("UPDATE Powers SET ipcs = 0 " & _
                               "WHERE power = " & Territory.PWR)
            Information(GetCapitalName(Territory.PWR) & " has been overrun by " & strPower & _
                        ". " & GetPowerName(Territory.PWR) & iIPCsCapital & " IPCs have been " & _
                        "confiscated And it cannot receive IPCs Until its capital Is liberated.")
            ' Need to know if these capitals have been captured
            If Territory.PWR = Germany And iPower = SovietUnion Then
                bBerlinLiberated = True
            Else If Territory.Name = "United Kingdom" Then
                bLondonCaptured = True
                If Not(bGerUSSRAtWar) And Not(bGerUSAtWar) Then                    
                    bGerUSSRAtWar = True
                    bGerUSAtWar = True
                    sqlDB.ExecNonQuery("UPDATE GameDetails SET gerussr = 1 AND gerus = 1")
                    Information("The Soviet Union and the United States declares war on Germany " & _
                                "due To London being overrun.")
                End If
            End If
        ' Liberating a Capital
        Else If GetPowersSide(iPower) = GetPowersSide(Territory.OrigPWR) And _
             bCapitalCaptured Then
            iChgPWR = Territory.OrigPWR
            If Territory.OrigPWR = France Then bParisLiberated = True
            ' Set Power to Captured
            sqlDB.ExecNonQuery("UPDATE Powers SET captured = 0 " & _
                               "WHERE power = " & iChgPWR)                           
            Information(GetCapitalName(Territory.OrigPWR) & " has been liberated by the " & strPower & _
                        ". " & GetPowerName(Territory.OrigPWR) & _
                        " can now receive IPCs for all territories that it still controls.")
        End If
    End If
    ' Liberating a Territory
    ' If you capture a Territory that was originally controlled by another member of your side, 
    ' you “liberate” the Territory. You don’t take control of it; instead, the original controller 
    ' regains the Territory
    ' If the original controller’s (the Power whose Territory you just liberated) capital is in
    ' enemy hands AT THE END OF THE TURN in which you would otherwise have liberated the Territory,
    ' you capture the Territory instead.
    If iPower <> Territory.OrigPWR And _
       GetPowersSide(iPower) = GetPowersSide(Territory.OrigPWR) Then
           If Not(bCapitalCaptured) Then
            iChgPWR = Territory.OrigPWR
            Information(strPower & " has liberated territory " & Territory.Name)
        Else
            Information(strPower & " has taken control of territory " & Territory.Name & _
                        " whose capital is in enemy hands.")
        End If
    End If
    ' Get the territory's icon
    Dim pnl As Panel = lsvTerritories.GetPanel(Position)
    Dim img As ImageView = pnl.GetView(0)
    Select iChgPWR
        Case Germany
            img.Bitmap = bmpGermany
        Case Italy
            img.Bitmap = bmpItaly
        Case Japan
            img.Bitmap = bmpJapan
        Case UKEurope
            img.Bitmap = bmpUKEurope
        Case France
            img.Bitmap = bmpFrance
        Case SovietUnion
            img.Bitmap = bmpUSSR
        Case UnitedStates
            img.Bitmap = bmpUS
        Case UKPacific
            img.Bitmap = bmpUKPacific
        Case China
            img.Bitmap = bmpChina
        Case ANZAC
            img.Bitmap = bmpANZAC
    End Select
    Territory.PWR = iChgPWR
    sqlDB.ExecNonQuery("UPDATE Territories SET power = " & iPower & _
                       " WHERE name = '" & Territory.Name & "'")
    Information("The " & strPower & " Power" & " has taken control of territory " & Territory.Name)
    iTerrIPCs = iTerrIPCs + Territory.IPC
End Sub
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Sorry it looked like this.

B4X:
'   Determine If the Power's capital has been captured
    If Territory.OrigPWR >= Germany And Territory.OrigPWR <= France Then
            bCapitalCaptured = Int2Bool(sqlDB.ExecQuerySingleResult("SELECT captured FROM Powers " & _
                                                            "WHERE Power = " & Territory.OrigPWR))
    End If
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Before you ask:
Germany is a constant int with a value of 1
France is a constant int with a value of 10

These are being used all over the app with no problems.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Perhaps change:

"SELECT captured FROM Powers " & _
"WHERE Power = " & Territory.OrigPWR

To:

"SELECT coalesce(captured, 1) FROM Powers " & _
"WHERE Power = " & Territory.OrigPWR


RBS
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
The statement "If 13 < 11 Then" was so the sql statement wouldn't get called for I knew that it would crash if it gets called. But it never gets there because the problem is that it crashes on the IF statement for some strange reason. And the crash is in Java not my code!
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Are you sure that the result returned from
B4X:
sqlDB.ExecQuerySingleResult("SELECT captured FROM Powers WHERE Power = " & Territory.OrigPWR)
is an INT?
Can you check what it really return?
Because it looks like the result arriving from
Int2Bool
it's not a Boolean.
At least I think this.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…