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

Discussion in 'Android Questions' started by Filippo, Nov 29, 2017.

  1. Filippo

    Filippo Expert Licensed User

    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?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Hard to say without seeing your code. It might be related to a call to DoEvents in a bad timing.

    Anyway, if the purpose of this timer is to update the label then it is better to move it to the activity as a process global variable. Enable it in Activity_Resume and disable it in Activity_Pause.
     
  3. Filippo

    Filippo Expert Licensed User

    I have removed all DoEvents in all my apps. :p

    That's basically my code in starter service:
    Code:
    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:
    Code:
    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.
     
  4. OliverA

    OliverA Well-Known Member Licensed User

  5. Erel

    Erel Administrator Staff Member Licensed User

    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.
     
  6. Filippo

    Filippo Expert Licensed User

    Thanks Erel, that's what I wanted to hear.
     
  7. Filippo

    Filippo Expert Licensed User

    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:

    Code:
    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
     
  8. Erel

    Erel Administrator Staff Member Licensed User

  9. Filippo

    Filippo Expert Licensed User

    Thanks a lot for allowing me to send you my project.
    I have just sent my project.
     
    ilan likes this.
  10. Erel

    Erel Administrator Staff Member Licensed User

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

    What are you using it for?
     
  11. Filippo

    Filippo Expert Licensed User

    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.
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    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.
     
    Filippo likes this.
  13. Filippo

    Filippo Expert Licensed User

    OK, then I have something to do again. :rolleyes:
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Two other things:
    1. Prefer the async dialogs such as Msgbox2Async over the modal dialogs.
    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.
     
  15. Filippo

    Filippo Expert Licensed User

    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".
     
  16. Filippo

    Filippo Expert Licensed User

    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.
     

    Attached Files:

  17. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the ClassCastException stack trace?
     
  18. Filippo

    Filippo Expert Licensed User

    b4a_07.PNG

    Code:
    Type SpeedItem(kmh As Double, starttime As Long, autostart As Int, Position As Int)
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    Based on the error message there is a case where an item of a different type got into this list.
     
    Filippo likes this.
  20. Filippo

    Filippo Expert Licensed User

    I have to agree with you again, here is my mistake. :(
    Code:
    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, 122False))
        
    End If
    End Sub
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice