parse-community / Parse-SDK-Flutter

The Dart/Flutter SDK for Parse Platform
https://parseplatform.org
Apache License 2.0
573 stars 188 forks source link

Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getFilesDir()' on a null object reference #983

Open Fanom2813 opened 8 months ago

Fanom2813 commented 8 months ago

New Issue Checklist

Issue Description

Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getFilesDir()' on a null object reference after following steps for push notification

Actual Outcome

it fails the first time the apk getting install , the second time i run debug , the app opens perfectly

Expected Outcome

Environment

Parse Flutter SDK

Server

Logs

E/AndroidRuntime( 5729): java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getFilesDir()' on a null object reference
E/AndroidRuntime( 5729):    at com.parse.ParseCorePlugins.getCurrentInstallationController(ParseCorePlugins.java:280)
E/AndroidRuntime( 5729):    at com.parse.ParseInstallation.getCurrentInstallationController(ParseInstallation.java:63)
E/AndroidRuntime( 5729):    at com.parse.ParseInstallation.getCurrentInstallation(ParseInstallation.java:68)
E/AndroidRuntime( 5729):    at com.parse.fcm.ParseFCM.register(ParseFCM.java:29)
E/AndroidRuntime( 5729):    at com.parse.fcm.ParseFirebaseMessagingService.onNewToken(ParseFirebaseMessagingService.java:16)
E/AndroidRuntime( 5729):    at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(FirebaseMessagingService.java:165)
E/AndroidRuntime( 5729):    at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$com-google-firebase-messaging-EnhancedIntentService(EnhancedIntentService.java:82)
E/AndroidRuntime( 5729):    at com.google.firebase.messaging.EnhancedIntentService$$ExternalSyntheticLambda0.run(Unknown Source:6)
E/AndroidRuntime( 5729):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
E/AndroidRuntime( 5729):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
E/AndroidRuntime( 5729):    at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@18.1.0:2)
E/AndroidRuntime( 5729):    at java.lang.Thread.run(Thread.java:1012)
parse-github-assistant[bot] commented 8 months ago

Thanks for opening this issue!

mbfakourii commented 8 months ago

Please, if possible, provide more explanations step by step

Fanom2813 commented 8 months ago

In my manifest

 <!--region Parse SDK-->

        <service android:name="com.parse.fcm.ParseFirebaseInstanceIdService" android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

        <service android:name="com.parse.fcm.ParseFirebaseMessagingService"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

        <receiver
            android:name="com.parse.ParsePushBroadcastReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>

        <!--endregion-->

I initialize like this

await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );

    await Parse().initialize(
      "key",
      "url",
      debug: true,
      coreStore: await CoreStoreSharedPreferences.getInstance(),
    );

    ParsePush.instance.initialize(FirebaseMessaging.instance, parseNotification:
        ParseNotification(onShowNotification: (message) async {
      print(message);
    }));
    FirebaseMessaging.onMessage
        .listen((message) => ParsePush.instance.onMessage(message));

    FirebaseMessaging.onBackgroundMessage(onBackgroundMessage);

    currentUser = await ParseUser.currentUser();

    if (currentUser != null) {
      await initInstallation();
    }
Future<void> initInstallation() async {
    final ParseInstallation installation =
        await ParseInstallation.currentInstallation();
    final ParseResponse response = await installation.create();
    print(response);
  }

when i do a fresh install i get java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getFilesDir()' on a null object reference however when i run the app a second time the error doesnt appear

i dont know it is a miss configration but install object is not saved in the database yet deviceToken is set and the object is well populated here is the log

I/flutter (27336): API Request (_Installation : ParseApiRQ.save) : I/flutter (27336): Uri: http://192.168.8.101:1337/parse/installations/Ipgt3ngJJt I/flutter (27336): Body: {"deviceToken":"token","pushType":"gcm","deviceType":"android","localeIdentifier":"en_US","timeZone":"Indian/Mayotte","appName":"app","appVersion":"0","appIdentifier":"id","parseVersion":"5.1.3"} I/flutter (27336): ----

server response :

{"code":101,"stack":"Error: Object not found for update.\n api/node_modules/parse-server/lib/RestWrite.js:1027:15\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"}

mbfakourii commented 8 months ago

In my manifest

 <!--region Parse SDK-->

        <service android:name="com.parse.fcm.ParseFirebaseInstanceIdService" android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

        <service android:name="com.parse.fcm.ParseFirebaseMessagingService"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

        <receiver
            android:name="com.parse.ParsePushBroadcastReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>

        <!--endregion-->

I initialize like this

await Firebase.initializeApp(
     options: DefaultFirebaseOptions.currentPlatform,
   );

   await Parse().initialize(
     "key",
     "url",
     debug: true,
     coreStore: await CoreStoreSharedPreferences.getInstance(),
   );

   ParsePush.instance.initialize(FirebaseMessaging.instance, parseNotification:
       ParseNotification(onShowNotification: (message) async {
     print(message);
   }));
   FirebaseMessaging.onMessage
       .listen((message) => ParsePush.instance.onMessage(message));

   FirebaseMessaging.onBackgroundMessage(onBackgroundMessage);

   currentUser = await ParseUser.currentUser();

   if (currentUser != null) {
     await initInstallation();
   }
Future<void> initInstallation() async {
    final ParseInstallation installation =
        await ParseInstallation.currentInstallation();
    final ParseResponse response = await installation.create();
    print(response);
  }

when i do a fresh install i get java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getFilesDir()' on a null object reference however when i run the app a second time the error doesnt appear

i dont know it is a miss configration but install object is not saved in the database yet deviceToken is set and the object is well populated here is the log

I/flutter (27336): API Request (_Installation : ParseApiRQ.save) : I/flutter (27336): Uri: http://192.168.8.101:1337/parse/installations/Ipgt3ngJJt I/flutter (27336): Body: {"deviceToken":"token","pushType":"gcm","deviceType":"android","localeIdentifier":"en_US","timeZone":"Indian/Mayotte","appName":"app","appVersion":"0","appIdentifier":"id","parseVersion":"5.1.3"} I/flutter (27336): ----

server response :

{"code":101,"stack":"Error: Object not found for update.\n api/node_modules/parse-server/lib/RestWrite.js:1027:15\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"}

These items you added in the manifest are for Parse Android, these items are not needed for Parse Flutter, please check the push notifications document again.

Fanom2813 commented 8 months ago

after removing the manifest, the app doesnt crash on fresh install , but initinstallation only works the first time when i reload the app i get

at least one ID field (deviceToken, installationId) must be specified in this operation {"code":135,"stack":"Error: at least one ID field (deviceToken, installationId) must be specified in this operation\n at RestWrite.handleInstallation (node_modules/parse-server/lib/RestWrite.js:954:11)\n at node_modules/parse-server/lib/RestWrite.js:105:17\n at runMicrotasks ()\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"}

thanks for your help

mbfakourii commented 8 months ago

after removing the manifest, the app doesnt crash on fresh install , but initinstallation only works the first time when i reload the app i get

at least one ID field (deviceToken, installationId) must be specified in this operation {"code":135,"stack":"Error: at least one ID field (deviceToken, installationId) must be specified in this operation\n at RestWrite.handleInstallation (node_modules/parse-server/lib/RestWrite.js:954:11)\n at node_modules/parse-server/lib/RestWrite.js:105:17\n at runMicrotasks ()\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"}

thanks for your help

Is the current user logged in?

Fanom2813 commented 8 months ago

after removing the manifest, the app doesnt crash on fresh install , but initinstallation only works the first time when i reload the app i get at least one ID field (deviceToken, installationId) must be specified in this operation {"code":135,"stack":"Error: at least one ID field (deviceToken, installationId) must be specified in this operation\n at RestWrite.handleInstallation (node_modules/parse-server/lib/RestWrite.js:954:11)\n at node_modules/parse-server/lib/RestWrite.js:105:17\n at runMicrotasks ()\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"} thanks for your help

Is the current user logged in?

when user is not logged in initinstallation completes normally , when i reload with user logged in it brings the above message