Android Question Strange crash on a SqlLite query,.

tigrot

Well-Known Member
Licensed User
Longtime User
Hi everybody:
I had this crash (signaled by Google):
Exception java.lang.RuntimeException: Object should first be initialized.
B4X:
anywheresoftware.b4a.sql.SQL.checkNull (SQL.java:48)
anywheresoftware.b4a.sql.SQL.ExecQuery (SQL.java:154)
it.whereami.logicdata.firebasemessaging._vvvvvvvvvvvvvvvvvvvvvvvvvv0 (firebasemessaging.java:448)
it.whereami.logicdata.firebasemessaging._fm_messagearrived (firebasemessaging.java:280)
java.lang.reflect.Method.invoke (Method.java)
anywheresoftware.b4a.BA.raiseEvent2 (BA.java:179)
anywheresoftware.b4a.BA$1.run (BA.java:303)
android.os.Handler.handleCallback (Handler.java:739)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:158)
android.app.ActivityThread.main (ActivityThread.java:7229)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)

the corresponding code is:
B4X:
Sub testclient (codice As String) As Boolean

    Dim nt() As String=Regex.Split(",",codice)
    Dim telno As String =nt(1) & nt(0)
    Dim cur As Cursor = Starter.SQL1.ExecQuery("select * from abilita where telno='" & telno & "'")
    If cur.RowCount=0 Then
        cur.Close
        Return True
    Else
        cur.Close
        Return False
    End If      
End Sub
The code references a Starter contained object (SQL1).
Is this a case in which Starter service has been stopped from system and the reception of a message from Firebase has found a null object?
I have no code at this level to restart Starter(I have actually added it) in case it's stopped by system.

Thank you in advance

Mauro Zanin
 

Cableguy

Expert
Licensed User
Longtime User
You could encapsulate the SQL call in a try/catch and check if the SQL is still initialized
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I would say yes, specially if returning to the app after it being on background for a long time.
Android S.O. manages the disposal of resources in a more or less "I need more space" kind of way, so one can never know for sure if the app has been terminated and resources disposed by it.
That is why EREL created the Starter Service, so that we can "control" how the app is coming back to foreground if not yet disposed, as opposed to opening in the same activity it went to background with...
But, I also thought that the starter was a long running service (sticky) that needn't be restarted "manually"...
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
I have seen that all IT professionals have same mental processes! Everywhere we live!
There must be something wrong in OS behaviour. this is a S7 with a lot of RAM, no need to stop a service(Crash firebase service says it has lot of spare memory).
Have a nice day...
 
Upvote 0

eps

Expert
Licensed User
Longtime User
We need to see more code to help.... i.e. where is Starter initiliazed? What about on resume, etc..

Have you tried debugging the issue or at least logging some information?

Also, where is this, nt, determined?

B4X:
Dim telno AsString =nt(1) & nt(0)
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Also, where is this, nt, determined?
On the previous line...it's a Regex.split result.
I assume that you are not stopping the starter service, right?

Are you initializing the SQL object in Service_Create of the starter service?

I never stopped starter, but if I look at process status, I see that Firebase service and starter service have different times, with starter restarting frequently and Firebase (which is sticky) never stops. I include a screen dump.
The starter is initialized in the service_start event, because if I do in service_create it's done only once and the program crashes.
An additional info: the screen dump was taken 20' ago, the process was restarted yesterday at about 17:00
 

Attachments

  • Screenshot_2017-05-17-09-41-37.png
    Screenshot_2017-05-17-09-41-37.png
    79 KB · Views: 290
Upvote 0

eps

Expert
Licensed User
Longtime User
Ah yes - sorry now I see nt... is codice always supplied - i.e. could that be null?

I guess you need to do a few 'isinitialized' checks? and re-initialise if not initialised?

Of course we don't know what the App is attempting to do...
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Of course it can, but I assumed that the starter service was running and initialized. This doesn't seem the case.
The sleeping App is waiting for a message thru Firebase Messaging. It can be once in many days(or never!).
I get the message and check its ID against a local database of authorized ID(in this case it's phone number). This is the check routine, straight and simple. This is the first time I get this error, the App is in beta and is tested by a group of users.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
True - I don't know your code and haven't run your App - I'd suggest putting logs in and seeing what's happening.

Don't assume anything!
 
Upvote 0

eps

Expert
Licensed User
Longtime User
You could log the issues and attempt to get the App to email you the log on a crash...

If, as you suspect it is one or more of the services stopping after an amount of time you could attempt to manually force a service to halt or go to sleep..
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
I have sorted out this issue. First let me describe the situation.
I have multiple services and two activities. One service is sticky.
There is no activity on starter service and on the other services(sticky one as well) so when activities are stopped, after a short time(about 20 minutes) the process is terminated and so starter service. The sticky service never ends and so the process and it's starter service are started again.
I had the chance to see the event looking at running processes.
The solution is to fire a timer event every some time(in my case 10 minutes) in starter service with no code in callback sub.
I don't know how many Apps are listening in background iinactive for long time, but if it's your case this is the fastest way to succede!
 
Upvote 0
Top