-
-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
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
java.lang.NullPointerException: Attempt to invoke virtual method 'io.flutter.plugin.common.PluginRegistry$RequestPermissionsResultListener com.lyokone.location.FlutterLocationService.getServiceRequestPermissionsResultListener()' on a null object reference #864
Comments
May I ask how to solve it |
What version of the plugin are you using? Please attach a Minimal, Reproducible Example. |
I'm facing a similar issue with the current version ( PlatformException(error, Attempt to write to field 'io.flutter.plugin.common.EventChannel$EventSink com.lyokone.location.FlutterLocation.events' on a null object reference in method 'void com.lyokone.location.StreamHandlerImpl.onListen(java.lang.Object, io.flutter.plugin.common.EventChannel$EventSink)', null, null) The error only occurs when using location from a separate isolate (in my case I try to start a location stream from a separate foreground service using |
@bartekpacia I am using location: ^5.0.1 |
Thanks for explaining. Could you attach minimal, reproducible examples? |
@bartekpacia sure. pressing the activate button works, pressing activate on other isolate does not work import 'dart:async';
import 'dart:isolate';
import 'package:flutter/material.dart';
import 'package:flutter_foreground_task/flutter_foreground_task.dart';
import 'package:location/location.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({super.key});
final location = Location();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FilledButton(
onPressed: activateLocation,
child: const Text("activate"),
),
FilledButton(
onPressed: activateLocationOtherIsolate,
child: const Text("activate on other isolate"),
),
],
),
),
);
}
Future<void> activateLocation() async {
await location.requestPermission();
await location.enableBackgroundMode();
final locationSubscription = location.onLocationChanged.listen(print);
Timer(const Duration(minutes: 5), () {
locationSubscription.cancel();
});
}
Future<void> activateLocationOtherIsolate() async {
// request permissions on main isolate
await location.requestPermission();
FlutterForegroundTask.init(
androidNotificationOptions: AndroidNotificationOptions(
channelId: 'notification_channel_id',
channelName: 'Foreground Notification',
),
iosNotificationOptions: const IOSNotificationOptions(),
foregroundTaskOptions: ForegroundTaskOptions(
interval: const Duration(minutes: 1).inMilliseconds,
),
);
await FlutterForegroundTask.startService(
notificationTitle: "title",
notificationText: "text",
callback: startCallback,
);
}
}
@pragma('vm:entry-point')
void startCallback() {
FlutterForegroundTask.setTaskHandler(MyTaskHandler());
}
class MyTaskHandler extends TaskHandler {
@override
Future<void> onStart(DateTime timestamp, SendPort? sendPort) async {}
@override
Future<void> onRepeatEvent(DateTime timestamp, SendPort? sendPort) async {
final location = Location();
await location.enableBackgroundMode();
final locationSubscription = location.onLocationChanged.listen(print);
Timer(const Duration(minutes: 5), () {
locationSubscription.cancel();
});
}
@override
Future<void> onDestroy(DateTime timestamp, SendPort? sendPort) async {}
} add to AndroidManifest.xml:
dependencies:
|
@bartekpacia It seems to be an initialization problem. The |
@bartekpacia @Lyokone any update on this? |
Tried running the code from commit hash code The issue still exists. I tried using flutter clean and running pub get again. |
Thanks for checking. I'll be happy to merge and release a fix but I don't have time to work on this. All contributions are welcome. |
this issue came up to me as well. |
Having the issue as well when running it from an isolate using flutter_foreground_task. |
Describe the bug
App crashing on very first app open
Tested on:
Other plugins:
Additional logs
D/FlutterGeolocator(20666): Attaching Geolocator to activity
D/FlutterGeolocator(20666): Detaching Geolocator from activity
E/AndroidRuntime(20666): FATAL EXCEPTION: main
E/AndroidRuntime(20666): Process: com.skieats.owner, PID: 20666
E/AndroidRuntime(20666): java.lang.RuntimeException: Unable to destroy activity {com.skieats.owner/com.skieats.owner.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'io.flutter.plugin.common.PluginRegistry$RequestPermissionsResultListener com.lyokone.location.FlutterLocationService.getServiceRequestPermissionsResultListener()' on a null object reference
E/AndroidRuntime(20666): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:6080)
E/AndroidRuntime(20666): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:6113)
E/AndroidRuntime(20666): at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:6460)
E/AndroidRuntime(20666): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:6341)
E/AndroidRuntime(20666): at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:71)
E/AndroidRuntime(20666): at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
E/AndroidRuntime(20666): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime(20666): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime(20666): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)
E/AndroidRuntime(20666): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(20666): at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime(20666): at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime(20666): at android.app.ActivityThread.main(ActivityThread.java:8757)
E/AndroidRuntime(20666): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(20666): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/AndroidRuntime(20666): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
E/AndroidRuntime(20666): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'io.flutter.plugin.common.PluginRegistry$RequestPermissionsResultListener com.lyokone.location.FlutterLocationService.getServiceRequestPermissionsResultListener()' on a null object reference
E/AndroidRuntime(20666): at com.lyokone.location.LocationPlugin.dispose(LocationPlugin.java:117)
E/AndroidRuntime(20666): at com.lyokone.location.LocationPlugin.detachActivity(LocationPlugin.java:56)
The text was updated successfully, but these errors were encountered: