Skip to content
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

PlatformException(STYLE IS NULL, The style is null. Has onStyleLoaded() already been invoked?, null) #384

Closed
hussenIbrahim opened this issue Aug 16, 2020 · 6 comments · Fixed by #418

Comments

@hussenIbrahim
Copy link

getting this error in released app Which causes symbols not to appear
on android real device
Flutter 1.21.0-7.0.pre • channel dev
package version 0.7.0

Non-fatal Exception: java.lang.Exception
PlatformException(STYLE IS NULL, The style is null. Has onStyleLoaded() already been invoked?, null)

this is my code

` MapboxMap(

      onStyleLoadedCallback: _onStyleLoadedCallback,
      trackCameraPosition: true,
      myLocationTrackingMode: MyLocationTrackingMode.Tracking,
      zoomGesturesEnabled: true,
      compassEnabled: false,
      myLocationEnabled: true,
      styleString: changeThemeNotifer.isDark()
          ? "assets/map_dark_style.json"
          : "assets/map_light_style.json",
      onMapCreated: _onMapCreated,
      initialCameraPosition: const CameraPosition(
          target: LatLng(0.0,0.0), zoom: 5),
    ),`
@m0nac0
Copy link
Collaborator

m0nac0 commented Aug 16, 2020

@hussenIbrahim Does this error occur when you add images? If yes, when do you add the images?

@hussenIbrahim
Copy link
Author

@hussenIbrahim Does this error occur when you add images? If yes, when do you add the images?

i don't know where or when it occurs and this error not every time thrown
i get the error from firebase Crashlytics
` void _onMapCreated(MapboxMapController controller) {
print("map created");
mapController = controller;
addImageFromAsset();
mapController.onSymbolTapped.add((argument) {
_onSymbolTapped(argument);
print(mapController.symbols.length);
});
}

Future addImageFromAsset() async {
ByteData bytes = await rootBundle.load("assets/icon.png");
Uint8List list = bytes.buffer.asUint8List();
mapController.addImage("icon", list);

}`

@hussenIbrahim
Copy link
Author

getting this error in profile mode

I/flutter ( 7556): RangeError (index): Invalid value: Only valid value is 0: 1 E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): Failed to handle method call E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): java.lang.NullPointerException: Attempt to invoke a virtual method on a null object reference E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at com.mapbox.mapboxgl.MapboxMapController.onMethodCall(MapboxMapController.java:740) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at android.os.MessageQueue.next(MessageQueue.java:323) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at android.os.Looper.loop(Looper.java:136) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at android.app.ActivityThread.main(ActivityThread.java:6776) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386) E/DartMessenger( 7556): Uncaught exception in binary message listener E/DartMessenger( 7556): java.lang.IllegalStateException: Reply already submitted E/DartMessenger( 7556): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:139) E/DartMessenger( 7556): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:246) E/DartMessenger( 7556): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/DartMessenger( 7556): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631) E/DartMessenger( 7556): at android.os.MessageQueue.nativePollOnce(Native Method) E/DartMessenger( 7556): at android.os.MessageQueue.next(MessageQueue.java:323) E/DartMessenger( 7556): at android.os.Looper.loop(Looper.java:136) E/DartMessenger( 7556): at android.app.ActivityThread.main(ActivityThread.java:6776) E/DartMessenger( 7556): at java.lang.reflect.Method.invoke(Native Method) E/DartMessenger( 7556): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) E/DartMessenger( 7556): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386) I/flutter ( 7556): Error caught by Crashlytics plugin <recordError>: I/flutter ( 7556): RangeError (index): Invalid value: Only valid value is 0: 1 E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): Failed to handle method call E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): java.lang.NullPointerException: Attempt to invoke a virtual method on a null object reference E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at com.mapbox.mapboxgl.MapboxMapController.onMethodCall(MapboxMapController.java:740) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at android.os.MessageQueue.next(MessageQueue.java:323) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at android.os.Looper.loop(Looper.java:136) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at android.app.ActivityThread.main(ActivityThread.java:6776) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) E/MethodChannel#plugins.flutter.io/mapbox_maps_0( 7556): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386) E/DartMessenger( 7556): Uncaught exception in binary message listener E/DartMessenger( 7556): java.lang.IllegalStateException: Reply already submitted E/DartMessenger( 7556): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:139) E/DartMessenger( 7556): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:246) E/DartMessenger( 7556): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/DartMessenger( 7556): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631) E/DartMessenger( 7556): at android.os.MessageQueue.nativePollOnce(Native Method) E/DartMessenger( 7556): at android.os.MessageQueue.next(MessageQueue.java:323) E/DartMessenger( 7556): at android.os.Looper.loop(Looper.java:136) E/DartMessenger( 7556): at android.app.ActivityThread.main(ActivityThread.java:6776) E/DartMessenger( 7556): at java.lang.reflect.Method.invoke(Native Method) E/DartMessenger( 7556): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) E/DartMessenger( 7556): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

@m0nac0
Copy link
Collaborator

m0nac0 commented Aug 17, 2020

@hussenIbrahim As noted in the documentation, please only call addImage() after onStyleLoaded callback has been invoked. Otherwise you might get this error, as images are added to a style, which isn't possible when the style hasn't been completely loaded, yet.

@hussenIbrahim
Copy link
Author

the error is solved for release and profile mode
but in debug mode on onStyleLoaded callback its invoked once when app is installed else it is not invoked until uninstall the app or clear the app cache
thanks @m0nac0

@m0nac0
Copy link
Collaborator

m0nac0 commented Aug 17, 2020

@hussenIbrahim Interesting, that sounds similar to what has been described in #347 (but only for iOS so far). Unfortunately I haven't been able to reproduce that, yet, but I'll look out for it if you also experience this on Android.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants