添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences android.content.Context.getSharedPreferences(java.lang.String, int)' on a null object reference Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences android.content.Context.getSharedPreferences(java.lang.String, int)' on a null object reference jbojcic1 opened this issue Dec 14, 2020 · 1 comment
  • Flutter info ( flutter doctor ):
  • Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, 1.22.4, on Mac OS X 10.15.4 19E287 darwin-x64, locale en-US)
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    [✓] Xcode - develop for iOS and macOS (Xcode 12.1)
    [!] Android Studio (version 4.1)
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
    [✓] IntelliJ IDEA Ultimate Edition (version 2020.3)
    [✓] VS Code (version 1.51.1)
    [!] Connected device
        ! No devices available
    
  • Plugin config:
  • final currentConfig = await bg.BackgroundGeolocation.state;
      Logger.debug('current bg geolocation config: ${currentConfig.toMap()}');
      bg.BackgroundGeolocation.ready(bg.Config(
              logLevel:
                  isProd ? bg.Config.LOG_LEVEL_ERROR : bg.Config.LOG_LEVEL_VERBOSE,
              reset: true,
              url: "${EnvironmentConfig.API_URL}/api/courierLocation",
              httpRootProperty: '.',
              locationTemplate:
                  '{"id":"<%= uuid %>","timeTakenUTC":"<%= timestamp %>","latitude":<%= latitude %>,"longitude":<%= longitude %>,"speedMeters":<%= speed %>,"isMoving":<%= is_moving %>}',
              params: {
                'deviceOs':
                    '${Platform.operatingSystem}:${Platform.operatingSystemVersion}',
                'appBuild': '${packageInfo.version}:${packageInfo.buildNumber}'
              method: 'POST',
              desiredAccuracy: Platform.isIOS
                  ? bg.Config.DESIRED_ACCURACY_NAVIGATION
                  : bg.Config.DESIRED_ACCURACY_HIGH,
              stopTimeout: 5,
              stationaryRadius: 200,
              stopOnStationary: false,
              stopOnTerminate: false,
              startOnBoot: true,
              distanceFilter: Platform.isAndroid ? 0 : 200.0,
              elasticityMultiplier: 2,
              maxRecordsToPersist: 5,
              enableHeadless: true,
              notification: bg.Notification(
                sticky: true,
                smallIcon: 'mipmap/notification_icon',
                largeIcon: 'mipmap/notification_icon',
              showsBackgroundLocationIndicator: true, // ios only,
              locationAuthorizationRequest: 'Always',
              authorization: currentConfig.authorization,
              backgroundPermissionRationale:
                  currentConfig.backgroundPermissionRationale,
              locationAuthorizationAlert: currentConfig.locationAuthorizationAlert,
              locationUpdateInterval: currentConfig.locationUpdateInterval,
              fastestLocationUpdateInterval:
                  currentConfig.fastestLocationUpdateInterval))
          .then((bg.State state) {
        Logger.debug('Background geolocation ready: ${state.toMap()}');
    

    Expected Behavior

    The app shouldn't crash

    Actual Behavior

    We got the following crash report from the google play console pre launch report:

    Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences android.content.Context.getSharedPreferences(java.lang.String, int)' on a null object reference
           at com.transistorsoft.tsbackgroundfetch.BackgroundFetchConfig$1.run(BackgroundFetchConfig.java)
           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
           at java.lang.Thread.run(Thread.java:818)
    

    Steps to Reproduce

    Not sure. I tried to reproduce in the emulator but wasn't able to.

    This comes from background_fetch, not background_geolocation and comes from Google simulating a crash.

    See transistorsoft/flutter_background_fetch#61