Android Question and further with the error "java.lang.NullPointerException:"

D

Deleted member 103

Guest
Hi,

the errors with "java.lang.NullPointerException:" do not stop. :(
error.PNG


Mein.java:
main.JPG


Starter.java:
starter.JPG

Is only a guess, but it may be that the timer is overstretched in starter service and the callsubs are not executed correctly?
If so, should the timer be moved to the main activity?
 
D

Deleted member 103

Guest
Hard to say without seeing your code. It might be related to a call to DoEvents in a bad timing.
I have removed all DoEvents in all my apps. :p

That's basically my code in starter service:
B4X:
Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.

    GpsTimer.Initialize("GpsTimer", 20)

End Sub

Sub Service_Start (StartingIntent As Intent)
    GpsTimer.Enabled = True
End Sub

Sub GpsTimer_Tick
    Dim time As Long = DateTime.Now

    CallSub2(Main, "ShowClock", time)
 
End Sub

and that in the main activity:
B4X:
Public Sub ShowClock(time As Long)
    dClock.Text = DateTime.time(time)
End Sub

One more thing, but I myself can not reproduce this error with my devices.
 
Upvote 0
D

Deleted member 103

Guest
It is better to move it to Main and manually enable and disable it. Otherwise the timer will keep firing while the app is in the background.
Thanks Erel, that's what I wanted to hear.
 
Upvote 0
D

Deleted member 103

Guest
It is better to move it to Main and manually enable and disable it. Otherwise the timer will keep firing while the app is in the background.
So I did it also, unfortunately, the error occurs but still.
I really do not know what to do yet. :(

Maybe the interval-time("GpsTimer", 20) is too small?

b4a_01.PNG

b4a_02.PNG


Main:

B4X:
Sub Globals
    Dim dClock As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
'the Label dClock is initialized in the designer

    If FirstTime = True Then
       GpsTimer.Initialize("GpsTimer", 20)
   End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   GpsTimer.Enabled = False
End Sub

Sub Activity_Resume
    GpsTimer.Enabled = True
End Sub

Sub GpsTimer_Tick
    Dim time As Long
    Dim DateTime1 As Long
    DateTime1   = DateTime.Now
    time        = DateTime1 - Starter.lngTimer + Starter.lngSecGpsToFunk
    dClock.Text = DateTime.time(time)
    ...
End Sub
 
Upvote 0
D

Deleted member 103

Guest
I see that you are using the Threading library. This can be related to these issues.

What are you using it for?
It will be used in my service "smCrono" for my countdown timer.
At the very beginning, I only had problems with the development of this app with the timer, so I use the threading library since then.
In the same iOS app, I use a timer, but here the timer is much better than in Android.
 
Upvote 0
D

Deleted member 103

Guest
I highly recommend you to avoid using the Threading library. B4A code was never intended to be executed on background threads.

I'm sure that you can implement it with timer or sleep.
OK, then I have something to do again. :rolleyes:
 
Upvote 0
D

Deleted member 103

Guest
2. I'm not familiar with fgCustomDialog implementation. I guess that it is also a modal dialog. Prefer to use CustomLayoutDialog from the Dialogs library.
The fgCustomDialog is a class with standard panel+Label+Button.

The modal dialogs I put only in non-critical sub, such as "Sub Show_About".
 
Upvote 0
D

Deleted member 103

Guest
Hi Erel,

I think the bugs have nothing to do with the threading library. :(
In another app, I removed the threading library last week, today I look in the Google Play console and find these errors.

The structure of both app is basically the same.
 

Attachments

  • b4a_03.PNG
    b4a_03.PNG
    24.4 KB · Views: 381
  • b4a_02.PNG
    b4a_02.PNG
    44.3 KB · Views: 413
  • b4a_01.PNG
    b4a_01.PNG
    47.5 KB · Views: 437
  • b4a_04.PNG
    b4a_04.PNG
    45.3 KB · Views: 377
  • b4a_05.PNG
    b4a_05.PNG
    39.2 KB · Views: 391
  • b4a_06.PNG
    b4a_06.PNG
    38.1 KB · Views: 389
Upvote 0
D

Deleted member 103

Guest
Gestern, 18:58 in der App-Version 37
Huawei P8 Lite (hwALE-H), 2048MB RAM, Android 6.0
Bericht 1 von 2
java.lang.ClassCastException
:
at fg.speedpilot_lite.main._activity_resume (main.java:640)
at java.lang.reflect.Method.invoke (Native Method)
at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent (BA.java:166)
at fg.speedpilot_lite.main.afterFirstLayout (main.java:108)
at fg.speedpilot_lite.main.access$000 (main.java:17)
at fg.speedpilot_lite.main$WaitForLayout.run (main.java:80)
at android.os.Handler.handleCallback (Handler.java:743)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:150)
at android.app.ActivityThread.main (ActivityThread.java:5621)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:684)

b4a_07.PNG


B4X:
    Type SpeedItem(kmh As Double, starttime As Long, autostart As Int, Position As Int)
 
Upvote 0
D

Deleted member 103

Guest
Based on the error message there is a case where an item of a different type got into this list.
I have to agree with you again, here is my mistake. :(
B4X:
Sub goReadIniFile
    Dim mp As Map
    mp = File.ReadMap(File.DirInternal, "Setup.ini")

    For Each key As String In mp.Keys
        Select key
            Case "AvarageSpeed"
                Starter.AvarageSpeed = mp.get(key)
            Case "lstAvarageSpeed"
                Starter.lstAvarageSpeed = StringToList(mp.get(key))
        End Select
    Next
    
    If Not(mp.ContainsKey("lstAvarageSpeed")) Then
        Starter.lstAvarageSpeed.Add(NumberFormat2(Starter.AvarageSpeed, 1, 2, 2, False))
    End If
End Sub
 
Upvote 0
Top