FloatingActionButton IllegalArgumentException

43 views
Skip to first unread message

nick.kr...@gmail.com

unread,
Apr 27, 2017, 5:28:40 PM4/27/17
to CodenameOne Discussions
I am using Netbeans IDE on the simulator. Here is the code I'm using where mapContainer is of class MapContainer. It seems to work fine on a device. Is this just simulator specific and nothing to worry about or am I doing something wrong?

FloatingActionButton fab = FloatingActionButton.createFAB(FontImage.MATERIAL_SORT);
fab.bindFabToContainer(this.getContentPane(), Component.LEFT, Component.BOTTOM);
this.addComponent(BorderLayout.CENTER, mapContainer);

As soon as fab.bindFabToContainer fires, I get about 100 of the following exception repeated:

[EDT] 0:0:6,790 - Exception: java.lang.IllegalArgumentException - create image failed for the given image data of length: 248
java.lang.IllegalArgumentException: create image failed for the given image data of length: 248
at com.codename1.ui.Image.createImage(Image.java:655)
at com.codename1.ui.EncodedImage.getInternal(EncodedImage.java:366)
at com.codename1.ui.EncodedImage.getInternalImpl(EncodedImage.java:341)
at com.codename1.ui.EncodedImage.drawImage(EncodedImage.java:532)
at com.codename1.ui.Graphics.drawImage(Graphics.java:586)
at com.codename1.maps.Tile.paint(Tile.java:121)
at com.codename1.maps.ProxyHttpTile.paint(ProxyHttpTile.java:87)
at com.codename1.maps.Tile.paint(Tile.java:138)
at com.codename1.maps.MapComponent.drawTiles(MapComponent.java:623)
at com.codename1.maps.MapComponent.paintmap(MapComponent.java:562)
at com.codename1.maps.MapComponent.paintBackground(MapComponent.java:210)
at com.codename1.ui.Component.paintBackgroundImpl(Component.java:1708)
at com.codename1.ui.Component.paintComponentBackground(Component.java:1665)
at com.codename1.ui.Container.paintComponentBackground(Container.java:2267)
at com.codename1.ui.Component.internalPaintImpl(Component.java:1318)
at com.codename1.ui.Component.paintInternalImpl(Component.java:1307)
at com.codename1.ui.Component.paintInternal(Component.java:1282)
at com.codename1.ui.Container.paint(Container.java:1439)
at com.codename1.ui.Component.internalPaintImpl(Component.java:1333)
at com.codename1.ui.Component.paintInternalImpl(Component.java:1307)
at com.codename1.ui.Component.paintInternal(Component.java:1282)
at com.codename1.ui.Container.paint(Container.java:1439)
at com.codename1.ui.Component.internalPaintImpl(Component.java:1333)
at com.codename1.ui.Component.paintInternalImpl(Component.java:1307)
at com.codename1.ui.Component.paintInternal(Component.java:1282)
at com.codename1.ui.Container.paint(Container.java:1439)
at com.codename1.ui.Component.internalPaintImpl(Component.java:1333)
at com.codename1.ui.Component.paintInternalImpl(Component.java:1307)
at com.codename1.ui.Component.paintInternal(Component.java:1282)
at com.codename1.ui.Container.paint(Container.java:1439)
at com.codename1.ui.Form.paint(Form.java:3128)
at com.codename1.ui.Component.internalPaintImpl(Component.java:1333)
at com.codename1.ui.Form.internalPaintImpl(Form.java:3138)
at com.codename1.ui.Component.paintInternalImpl(Component.java:1307)
at com.codename1.ui.Component.paintInternal(Component.java:1282)
at com.codename1.ui.Component.paintInternal(Component.java:1250)
at com.codename1.ui.Component.paintComponent(Component.java:1535)
at com.codename1.ui.Component.paintComponent(Component.java:1482)
at com.codename1.impl.CodenameOneImplementation.paintDirty(CodenameOneImplementation.java:588)
at com.codename1.impl.javase.JavaSEPort.paintDirty(JavaSEPort.java:1278)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1077)
at com.codename1.ui.Display.mainEDTLoop(Display.java:999)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

Steve Hannah

unread,
Apr 28, 2017, 11:54:40 AM4/28/17
to codenameone...@googlegroups.com
That should work (I just copied and pasted that code into my Google maps test and it worked).  It is possible that some network issue prevented downloading the times from open street map.  I recommend using a google maps Javascript key and passing it to the MapContainer constructor so that the simulator will use Google maps in a webview instead of falling back to the tile-based MapComponent.  That will yield results closer to the device.

Best regards

Steve

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/c6aac539-9f83-4fb0-9757-a6826c4406b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Software Developer
Codename One

nick.kr...@gmail.com

unread,
Apr 28, 2017, 12:05:02 PM4/28/17
to CodenameOne Discussions
I am passing a GMaps key in the constructor:

if (Display.getInstance().getPlatformName().equals("and")) {
            cnt = new MapContainer(new GoogleMapsProvider(Constants.ANDROID_GMAPS_API_KEY));
        } else {
            cnt = new MapContainer(new GoogleMapsProvider(Constants.APPLE_GMAPS_API_KEY));
}

I'm assuming if it was a real issue on the device, it would be throwing exceptions?

Steve Hannah

unread,
Apr 28, 2017, 12:18:08 PM4/28/17
to codenameone...@googlegroups.com
That is likely the problem.  getPlatformName() will return the name of the platform that is being simulated on the simulator  (You can use Display.isSimulator() to check if you're in the simulator).  If you pass in a maps provider, that is ONLY used in the simulator, and it will cause the MapContainer to fall back to use the old MapComponent when in the simulator.  Further, GoogleMapsProvider uses the static maps API (https://developers.google.com/maps/documentation/static-maps/), but it looks like you are passing in keys for the Android and iOS SDKs - neither of which will work with the static maps API.

If you simply pass in a string with your Javascript API key (rather than passing in a MapProvider), it will cause the simulator to use the Google maps vector based API inside a webview, which will be closer to the way it works on device.

There is an example here:

Steve

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.

For more options, visit https://groups.google.com/d/optout.

Krause Nick

unread,
Apr 28, 2017, 12:21:48 PM4/28/17
to codenameone...@googlegroups.com
Alright, good to know. Thanks Steve! This can be closed out now.

On Fri, Apr 28, 2017 at 9:18 AM, Steve Hannah <steve....@codenameone.com> wrote:
That is likely the problem.  getPlatformName() will return the name of the platform that is being simulated on the simulator  (You can use Display.isSimulator() to check if you're in the simulator).  If you pass in a maps provider, that is ONLY used in the simulator, and it will cause the MapContainer to fall back to use the old MapComponent when in the simulator.  Further, GoogleMapsProvider uses the static maps API (https://developers.google.com/maps/documentation/static-maps/), but it looks like you are passing in keys for the Android and iOS SDKs - neither of which will work with the static maps API.

If you simply pass in a string with your Javascript API key (rather than passing in a MapProvider), it will cause the simulator to use the Google maps vector based API inside a webview, which will be closer to the way it works on device.

There is an example here:

Steve
On Fri, Apr 28, 2017 at 9:05 AM, <nick.kr...@gmail.com> wrote:
I am passing a GMaps key in the constructor:

if (Display.getInstance().getPlatformName().equals("and")) {
            cnt = new MapContainer(new GoogleMapsProvider(Constants.ANDROID_GMAPS_API_KEY));
        } else {
            cnt = new MapContainer(new GoogleMapsProvider(Constants.APPLE_GMAPS_API_KEY));
}

I'm assuming if it was a real issue on the device, it would be throwing exceptions?

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsubscr...@googlegroups.com.



--
Steve Hannah
Software Developer
Codename One

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/clQ-3bQAGJk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discussions+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages