Android Question Fatal Exception: java.lang.RuntimeException: null object reference

Discussion in 'Android Questions' started by PierPaduan, Apr 29, 2019.

  1. PierPaduan

    PierPaduan Active Member Licensed User

    Hi everybody.
    Crashlytics gave me the following error. It has happened only 3 times on a Nokia 3.1 with Android 9.
    The line "service1.java:229" in service1.java should be the following:
    Code:
    mostCurrent._service.StartForeground((int) (1),(android.app.Notification)(_vvvvvvvvvvvvvvvvvvvvvvvvvvv0.getObject()));
    And it should correspond to the StartForeground line below:
    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim nNotify As Notification 
    End Sub

    Sub Service_Create
        nNotify.Initialize
        nNotify.Icon = 
    ""      
        nNotify.Sound=
    False
        nNotify.Vibrate=
    False
        nNotify.Light=
    False
        nNotify.OnGoingEvent=
    True
        nNotify.SetInfo(
    """""")    
    End Sub

    Sub Service_Start (StartingIntent As Intent)
        
    Service.StartForeground(1,nNotify)
        
    '.......
    Am I doing something wrong?
    Can someone give to me an advice?
    Thanks a Lot.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Which version of B4A are you using?
     
  3. PierPaduan

    PierPaduan Active Member Licensed User

    B4A version 8.80
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    What is causing the service to start?
     
  5. PierPaduan

    PierPaduan Active Member Licensed User

    In this app there is a "Timer" activity that shows a countdown to the user.
    If the user put the activity in background, the service starts every second and show to the user a notification with the remaining time.

    The service starts from:
    • the "Timer" Activity_Create (but really I don't remember why I decided this years ago, I tried now removing this ServiceStart and all works anyway),
    • the "Timer" Activity_Pause,
    • the Service_Start with a StartServiceAt(... + 1 second ...)
     
  6. DonManfred

    DonManfred Expert Licensed User

    Android will not allow you to restart a service in this interval.
    Set the interval to restart the serrvice after 15 MINUTES or more.

    Alternatively use a Foreground service and a timer.
     
  7. PierPaduan

    PierPaduan Active Member Licensed User

    Implemented!
    It works better than before.
    Thanks aLot.
     
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