React-native-background-geolocation: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.configure(com.marianhello.bgloc.Config)' on a null object reference

Created on 24 May 2018  路  10Comments  路  Source: mauron85/react-native-background-geolocation

Your Environment

  • Plugin version: 0.5.0-alpha.30
  • Platform: Android
  • OS version: Oreo 8.0
  • Device manufacturer and model: Samsung Galaxy S8
  • React Native version: 0.55.4

Actual Behavior

Sometimes the plugin crashes, randomly.

Steps to Reproduce

Start the app, many times, and randomly once will crash.
The plugin is not started, just configured.

Debug logs

Only the error message in issue title.

export default class App extends Component<Props, State> {

  componentDidMount() {
    // . . . . .
    this.initializeBackgroundGeolocation();
   //  . . . . . . 
  }

private initializeBackgroundGeolocation() {

    if (__DEV__) {
      console.log('App.initializeBackgroundGeolocation Call');
    }

    const options = {

      debug: __DEV__,

      stopOnTerminate: true,

      desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,

      // locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
      locationProvider: BackgroundGeolocation.DISTANCE_FILTER_PROVIDER,

      // Android
      interval: 10000,
      startOnBoot: false,
      notificationTitle: 'Background tracking',
      notificationText: 'enabled',
      // notificationIconColor: '#FF0000',
      // notificationIconSmall: '',
      // notificationIconLarge: '',

      // iOS
      // activityType: '',
      pauseLocationUpdates: false,
      saveBatteryOnBackground: false,

      // DISTANCE_FILTER_PROVIDER
      distanceFilter: 8,
      stationaryRadius: 15,

      // ACTIVITY_PROVIDER
      activitiesInterval: 10000,
      fastestInterval: 5000,
      stopOnStillActivity: false, // deprecated

    };

    try {
      BackgroundGeolocation.configure(options);
    } catch (e) {

      Sentry.captureException(e);

      if (__DEV__) {
        console.error('BackgroundGeolocation Configuration Error');
        console.error(e);
      }
    }

    BackgroundGeolocation.checkStatus(status => {

      // . . . . .     

    });

  }
}
bug

All 10 comments

Please send me some plugin logs?
I'm specially interested in logged events:

  1. App will be resumed
  2. Service connected
  3. Service configured with...

Also few more questions for you.

  1. Does it crash only when app is launched from launcher?
  2. Does it crash only when app is started by tapping on notification?
  3. Does it crash after screen rotate?

Added next lines:


componentDidMount() {

  if (__DEV__) {
    console.log('App.componentDidMount');
  }

  this.addEvents();

  this.initializeBackgroundGeolocation();

}

addEvents() {
    BackgroundGeolocation.on('stationary', () => console.log('BackgroundGeolocation Stationary'));
    BackgroundGeolocation.on('activity', (activity) => console.log('BackgroundGeolocation Activity', JSON.stringify(activity)));
    BackgroundGeolocation.on('start', () => console.log('BackgroundGeolocation Start'));
    BackgroundGeolocation.on('stop', () => console.log('BackgroundGeolocation Stop'));
    BackgroundGeolocation.on('background', () => console.log('BackgroundGeolocation Background'));
    BackgroundGeolocation.on('foreground', () => console.log('BackgroundGeolocation Foreground'));
    BackgroundGeolocation.on('authorization', (status) => console.log('BackgroundGeolocation Authorization', JSON.stringify(status)));
    BackgroundGeolocation.on('error', (error) => console.log('BackgroundGeolocation Error', JSON.stringify(error)));
    BackgroundGeolocation.on('location', () => console.log('BackgroundGeolocation Location'));
}

initializeBackgroundGeolocation() {

  if (__DEV__ || true) {
    console.log('App.initializeBackgroundGeolocation Call');
  }

  const options = { . . . };

  try {
    BackgroundGeolocation.configure(options);
  } catch (e) {

    Sentry.captureException(e);

    if (__DEV__ || true) {
      console.error('BackgroundGeolocation Configuration Error');
      console.error(e);
    }
  }

  BackgroundGeolocation.checkStatus(status => {

    if (__DEV__ || true) {
      console.log('BackgroundGeolocation Status', JSON.stringify(status));
    }

    // . . . . .
  });

}

Will send the logs, when it crash. Is this enough?

Uhh. Last time it crashed in android emulator after reload (RR). On my phone (Galaxy S8), as I remember, crashed when started from launcher. But will test it in different situations.

Here is the first.
The app was started in emulator by tapping on (scheduled) notification (react-native-push-notification).
Before was started many times successfully.

05-24 15:00:06.823 14678 14678 D ReactNative: ReactInstanceManager.attachRootViewToInstance()
05-24 15:00:06.829 14678 14705 I ReactNativeJS: Running application "..." with appParams: {"rootTag":1}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
05-24 15:00:07.119 14678 14705 I ReactNativeJS: App.componentDidMount
05-24 15:00:07.121 14678 14705 I ReactNativeJS: App.addEvents
05-24 15:00:07.148 14678 14705 I ReactNativeJS: App.loadVariables
05-24 15:00:07.165 14678 14705 I ReactNativeJS: App.initializeOneSignal Call
05-24 15:00:07.167 14678 14705 I ReactNativeJS: App.initializePushNotification Call
05-24 15:00:07.168 14678 14705 I ReactNativeJS: App.initializeBackgroundFetch Call
05-24 15:00:07.175 14678 14705 I ReactNativeJS: App.initializeBackgroundGeolocation Call
05-24 15:00:07.202 14678 14705 I ReactNativeJS: BackgroundGeolocation Foreground
05-24 15:00:07.206 14678 14705 I ReactNativeJS: 'App.onChangeAppState', 'active'
05-24 15:00:08.076 14678 14705 I ReactNativeJS: App.onPushNotification
05-24 15:00:08.076 14678 14705 I ReactNativeJS: { foreground: false,
05-24 15:00:08.076 14678 14705 I ReactNativeJS:   finish: [Function: finish],
05-24 15:00:08.076 14678 14705 I ReactNativeJS:   fireDate: 1527166730110,
05-24 15:00:08.076 14678 14705 I ReactNativeJS:   userInteraction: true,
05-24 15:00:08.076 14678 14705 I ReactNativeJS:   id: '-1195024904',
05-24 15:00:08.076 14678 14705 I ReactNativeJS:   ..... }
05-24 15:00:08.082 14678 14705 I ReactNativeJS: 'BackgroundGeolocation Status', '{"authorization":1,"locationServicesEnabled":true,"hasPermissions":true,"isRunning":false}'
05-24 15:00:09.590 14678 14705 E ReactNativeJS: RNBackgroundGeolocation: Configuration error: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.configure(com.marianhello.bgloc.Config)' on a null object reference
RNBackgroundGeolocation: Configuration error: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.configure(com.marianhello.bgloc.Config)' on a null object reference
handleException
    G:\app\myapp-react\node_modules\react-native\Libraries\Core\ExceptionsManager.js:60:18
handleError
    G:\app\myapp-react\node_modules\react-native\Libraries\Core\InitializeCore.js:69:40
<unknown>
    G:\app\myapp-react\node_modules\react-native-sentry\lib\raven-plugin.js:163:23
<unknown>
    G:\app\myapp-react\node_modules\react-native-sentry\lib\Sentry.js:43:41
emit
    G:\app\myapp-react\node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:180:12
__callFunction
    G:\app\myapp-react\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:351:47
<unknown>
    G:\app\myapp-react\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:116:26
__guardSafe
    G:\app\myapp-react\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:314:6
callFunctionReturnFlushedQueue
    G:\app\myapp-react\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:115:17

Thanks. That is what I though. If app is started from notification, configure is called from main thread instead of special react-native thread and there is apparently race condition in this case. I think I already found it. So wait for fix.

any schedule to fix this error? I face same error. I need to use this library ASAP.
or temp solutions?
thanks for your hard work.

@gabrieljo you may consider that this is an open source project, if you really need to usit ASAP, then make your pull request, work harder, or better hire some developer that can make work that you can't.

the time that @mauron85 is wasting here, i think he never got any money from here, just saying...

It is a bit annoying bug, but I have no idea where, and how to fix it. I am just in dev phase, so I wait patiently...

I am also running into this bug after upgrading to Gradle 4 and using the alpha 34 branch. It happens for me when running react-native run-android after the app has already been installed. It works when I uninstall the app and then reinstall it. Please let me know if any logs would be helpful for getting it fixed.

fixed in 0.5.0-alpha.36

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anishroff picture anishroff  路  4Comments

iocuydi picture iocuydi  路  4Comments

Daavidaviid picture Daavidaviid  路  3Comments

HaswinVidanage picture HaswinVidanage  路  3Comments

aemdy picture aemdy  路  4Comments