Android Question help debugging a crash

marcick

Well-Known Member
Licensed User
Longtime User
Hi all,
I have an imageview named "SyncIcon" in the main page that is set visible during some operations (network request) and not visible when job is done.
All works as expected, but it happens sometimes that I have a crash with this log:

B4X:
~e:main_timer_sms_tick (java line: 7632)
~e:java.lang.NullPointerException: Attempt to invoke virtual method 'boolean anywheresoftware.b4a.objects.ImageViewWrapper.getVisible()' on a null object reference

The java line 7632 is:

B4X:
 //BA.debugLineNum = 803;BA.debugLine="SyncIcon.Visible=MySub.ShowSyncIcon";
mostCurrent._syncicon.setVisible(mostCurrent._vvvvvvvvvvvvvvvvvvvvv3._vvvvvv1);

(ShowSyncIcon is a boolean)

Any idea where I can investigate ?
 

Cableguy

Expert
Licensed User
Longtime User
Seems to be related to the timer_SMS_tick sub...
You should avoid composite sub names like that one since the compiler will search for the "_" to list thé évents and that may cause unexpected behavior...
You'd be safer using timersms, or smstimer or even SMSTimer...
Without any code to analize, and with the litle info you provider, there's just so much WE can offer as help
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Thanks, that's interesting and I will consider your suggestion.
But in this case the timer event is alwais raised, its' the line SyncIcon.Visible= .... that generate the error.
Would be interesting to know the exact meaning of that error.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I have no idea what is mostcurrent .....
But why SYncIcon should be null ? It is countinuously set visible and not visible during program execution.
I'm unable to reproduce here the crash, it happens sometimes to my customers and I have the log thanks to the logcat in the starter service that send me the email.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I add some details.
The timer_SMS is called every 1s and inside the event the imageview i set to visible or not according to the boolean value of SyncIcon.
I have added now a try-catch in the whole timer event but I'm not sure that that error is random and isolated or once it happens the whole code is compromised.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I can't understand what's happening.
The error in the first post was genereted inside a Timer_Tick event.
So I have added a try-catch in the whole routine, to avoid the crash and just log the error in a file

B4X:
Sub TimerSMS_tick   
    Try
    CheckGcm
    If WaitNavigationPoint=True Then
        If IconNavigation.Visible=True Then
            IconNavigation.Visible=False
        Else
            IconNavigation.Visible=True
        End If
   .....
.......
......
......
    Catch
        MySub.WriteLog("TimerSMS_Tick, " & LastException.Message)
    End Try
End Sub

What happens now is that I still have the crash but like this:

B4X:
~e:main_timersms_tick (java line: 7757)
~e:java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Exception anywheresoftware.b4a.BA.getLastException()' on a null object reference
~e:    at anywheresoftware.b4a.keywords.Common.LastException(Common.java:662)
~e:    at it.elettronicablancato.bmap4aw.main._timersms_tick(main.java:7757)

The Java line 7757 is this:

B4X:
 }
       catch (Exception e112) {
            processBA.setLastException(e112); //BA.debugLineNum = 870;BA.debugLine="MySub.WriteLog(\"TimerSMS_Tick, \" & LastException";
mostCurrent._vvvvvvvvvvvvvvvvvvvvv5._vvvvvvvvvvvv1(mostCurrent.activityBA,"TimerSMS_Tick, "+anywheresoftware.b4a.keywords.Common.LastException(mostCurrent.activityBA).getMessage());
};
//BA.debugLineNum = 872;BA.debugLine="End Sub";
return "";
}

Anybody is able to understand why the try-catch doesn't work as expected and is not able to log the LastException.message ?
Please note I have the logcat in the Starter Service, but, as far as I know, if you put a try-catch anywhere it is managed separately and the error is not trapped by the logcat
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
not able to log the LastException.message
There is no exception trown so lastexception is not initialized.

I would try to check if the Exception is initialized first...

Something like
B4X:
Catch
if LastException. isInitialized then
    MySub.WriteLog("TimerSMS_Tick, Exception: " & LastException.Message)EndTry
else
    MySub.WriteLog("TimerSMS_Tick, An error occured")
EndTry
end if
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Hi Donmanfred, do you mean that there are errors that doesn't have an Exception message ? An Android bug ?
I'll try that, thanks
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
I'm not great at understanding the error reports that Google likes to provide, but it seems to me that something has occurred in your App to dispose of the IconNavigation image and so it's causing an exception when you request its visible state.
Attempt to invoke virtual method 'boolean anywheresoftware.b4a.objects.ImageViewWrapper.getVisible()' on a null object reference

Therefore I would check if the object IsInitialised before checking if visible.

B4X:
Sub TimerSMS_tick
    CheckGcm
    If WaitNavigationPoint=True Then
        If IconNavigation.IsInitialised Then 'check object first before checking visibility
            If IconNavigation.Visible=True Then
                 IconNavigation.Visible=False
            Else
                 IconNavigation.Visible=True
            End If
        End If
 .....
.......
......
......
End Sub
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Therefore I would check if the object IsInitialised before checking if visible.

Thank you.
If I could reproduce the problem here it would be easier to arrive to some conclusion.
But happens only on several customer devices.
I'm a bit disoriented. There are tenth of situation like this inside the program, I can't check if everything is initialized before using it. And why the exception does not have an exception message ?

Some more info:
There are some icons placed over a googlemap. I use Bringtofront with them. They are not markers, just flags that in some situation are visible or flashing in the top right corner of the map (the timer_SMS event manage their visibility as you see).
The map can represent normal googlemap, satellite or mapsforge staticmap.
It seems true that when the user select mapsforge as map type, the crash is absent. If the user select some online googlemap, then, during normal operation and after a time "x" the crash can happen.
Explain this is really hard for me.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I would try to check if the Exception is initialized first...

Me again.
I have modified the try-catch as suggested

B4X:
    Catch
        If LastException.IsInitialized=True Then
            MySub.WriteLog("TimerSMS_Tick, " & LastException.Message)
        Else
            MySub.WriteLog("TimerSMS_Tick, error without exception")
        End If
    End Try

The crash in the TimerSMS routine still occour and are not managed as expected:

B4X:
~e:main_timersms_tick (java line: 7757)
~e:java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Exception anywheresoftware.b4a.BA.getLastException()' on a null object reference
~e:    at anywheresoftware.b4a.keywords.Common.LastException(Common.java:662)
~e:    at it.elettronicablancato.bmap4aw.main._timersms_tick(main.java:7757)
~e:    at java.lang.reflect.Method.invoke(Native Method)
~e:    at java.lang.reflect.Method.invoke(Method.java:372)
~e:    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
~e:    at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)

The java line 7757 is in the picture
Help .....
 

Attachments

  • Cattura.JPG
    Cattura.JPG
    93.7 KB · Views: 259
Upvote 0
Top