rafaelsetragni / awesome_notifications

A complete solution to create Local Notifications and Push Notifications, throught Firebase or another services, using Flutter.
https://discord.awesome-notifications.carda.me
Apache License 2.0
732 stars 322 forks source link

NullPointerException: Context.getPackageName()' on a null object reference #910

Closed PeperMarkreel closed 4 months ago

PeperMarkreel commented 6 months ago

Rules

To report a bug and help us to provide the solution as fast as possible, please follow the instructions below:

1 - Describe the bug

From Firebase crashlytics.

Fatal Exception: java.lang.RuntimeException: Unable to instantiate service me.carda.awesome_notifications.core.managers.StatusBarManager: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
       at android.app.ActivityThread.handleCreateService(ActivityThread.java:2862)
       at android.app.ActivityThread.-wrap4(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5421)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
       at android.content.ContextWrapper.getPackageName(ContextWrapper.java:133)
       at me.carda.awesome_notifications.core.AwesomeNotifications.getPackageName(AwesomeNotifications.java:90)
       at me.carda.awesome_notifications.core.managers.StatusBarManager.<init>(StatusBarManager.java:54)
       at java.lang.Class.newInstance(Class.java)
       at android.app.ActivityThread.handleCreateService(ActivityThread.java:2859)
       at android.app.ActivityThread.-wrap4(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5421)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

2 - Provide us as much information as possible

To help us to understand your issue, provide with your bug report all the relevant informations, such as:

I have added to app\build.gradle to mitigate the sharedpreferences bug.

android {
  buildTypes{
    relase{
            minifyEnabled false
            shrinkResources false
    }
  }
}
  late Future<void> localNotificationsFuture;
(...)
  localNotificationsFuture =
      NotificationController.initializeLocalNotifications();

(...)
  localNotificationsFuture.then((value) async {
    bool notificationsAllowed =
        await AwesomeNotifications().isNotificationAllowed();
    if (!notificationsAllowed) {
      AwesomeNotifications()
          .requestPermissionToSendNotifications()
          .then((value) {
        if (value) {
          scheduleNotifications(user);
        }
      });
    } else {
      scheduleNotifications(user);
    }
  });

[√] Flutter (Channel stable, 3.16.5, on Microsoft Windows [Version 10.0.22631.2861], locale en-NL) • Flutter version 3.16.5 on channel stable at c:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 78666c8dc5 (9 days ago), 2023-12-19 16:14:14 -0800 • Engine revision 3f3e560236 • Dart version 3.2.3 • DevTools version 2.28.4

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at C:\Users\PeperMarkreel\AppData\Local\Android\sdk • Platform android-34, build-tools 34.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.6) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.7.34221.43 • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2023.1) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] VS Code (version 1.85.1) • VS Code at C:\Users\PeperMarkreel\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.78.0

[√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22631.2861] • Chrome (web) • chrome • web-javascript • Google Chrome 120.0.6099.130 • Edge (web) • edge • web-javascript • Microsoft Edge 120.0.2210.91

[√] Network resources • All expected network resources are available.

• No issues found!


OBS: To post a source code in your issue, please use the markdown below:

```Dart
print('Your source code goes here');

3 - How To Reproduce the Error

I have no idea.

github-actions[bot] commented 4 months ago

This issue was automatically closed due inactivity, but can be reopened at any time.