Problem loading mapcontainer --> black screen

26 views
Skip to first unread message

Peter Bell

unread,
Sep 17, 2019, 3:33:58 PM9/17/19
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans
Simulator
Device LG 4C

I have build an app with uses native googlemaps.cn1lib. The app conainns a tabbed view with a side toolbar.
in one of the tabs i got the google map.

i have a problem with loading the object. when i open the app i got a black screen. when i open the app a second time then the app start normal and i get the first tab. i tried a workarround with a splash screen and then load the mapcontainer when i go to the map tab. But that didn't work because the app crashes. 
So how can i solve this problem. Any clues?

Greetings
Peter Bell




Steve Hannah

unread,
Sep 17, 2019, 4:42:30 PM9/17/19
to codenameone...@googlegroups.com
What version of JDK?  When the app crashes, do you get an error message in your console?

--
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-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/8523e9ba-a900-48ff-be96-599496cf749a%40googlegroups.com.


--
Steve Hannah
Software Developer
Codename One

Peter Bell

unread,
Sep 17, 2019, 5:36:19 PM9/17/19
to CodenameOne Discussions
i use jdk 1.8.0_121 and i dont get an error message  on the device and in the simulator

Op dinsdag 17 september 2019 21:33:58 UTC+2 schreef Peter Bell:

Peter Bell

unread,
Sep 17, 2019, 5:47:14 PM9/17/19
to CodenameOne Discussions
i tried also to move the map to another form . but also here i have to go out the app and return to see the map/ But the problem becomes bigger because the bittons name doesn't change anymore when l click on the button

Shai Almog

unread,
Sep 17, 2019, 10:52:35 PM9/17/19
to CodenameOne Discussions
Does this exact behavior happen in the device and the simulator?
Are you seeing the JavaScript maps or the native SDK maps when running on the device?
When you generated the keys is it possible you restricted them in any way?

Peter Bell

unread,
Sep 18, 2019, 2:01:12 AM9/18/19
to CodenameOne Discussions
I havent the problem on the simulator but only on the device .the map wont load the first time on the device and load the second time fast.
I will check the permissions widh keys do i need for the android version

Steve Hannah

unread,
Sep 18, 2019, 7:46:13 AM9/18/19
to codenameone...@googlegroups.com
Check out the configuration section of the readme

Specifically, the build hint:
android.xapplication=<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="YOUR_ANDROID_API_KEY"/>

On Tue, Sep 17, 2019 at 11:01 PM Peter Bell <pbellpi...@gmail.com> wrote:
I havent the problem on the simulator but only on the device .the map wont load the first time on the device and load the second time fast.
I will check the permissions widh keys do i need for the android version

--
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-discu...@googlegroups.com.

Peter Bell

unread,
Sep 19, 2019, 3:44:36 PM9/19/19
to CodenameOne Discussions
Hi steve

The problem of the black screen is solved. The build hints were not correct updated,
But now i face another problem . The map is not filling the screen.

So i now see the googlemaps on my device but the map height is very small. The map doesnt fill the screen.

My code is

Cnt = new MapContainer();
Cnt.setMapType(1);
Container Kaart = Boxlayout.enclosecenter(cnt);
Form hi = new Form (“app”, new BorderLayout());
hi.addComponent(BorderLayout.CENTER, Kaart);
Hi.show()

Any suggestions?

Steve Hannah

unread,
Sep 19, 2019, 4:00:48 PM9/19/19
to codenameone...@googlegroups.com
Can you show a screenshot?  That almost certainly isn't your actual code, since there are typos there.  There may be clues in the details if you post the exact code.

--
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-discu...@googlegroups.com.

Peter Bell

unread,
Sep 19, 2019, 5:30:28 PM9/19/19
to CodenameOne Discussions

The code is

public void start() {

l= 0;


if(current != null){
current.show();
return;
}

hi = new Form("TalkingGps", new BorderLayout());
MapContainer cnt = new MapContainer();

// cnt = new MapContainer(provider);
// String tileLayer= "http://t1.openseamap.org/seamark/";

// cnt.addTilelayer(tileLayer);


cnt.addLongPressListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {
t.setSelectedIndex(0);

}
});



Kaart= BoxLayout.encloseYCenter(cnt);




cnt.addTapListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {

if ((routenw == true)) {
int x = evt.getX()-cnt.getAbsoluteX(); ;
int y = evt.getY()-cnt.getAbsoluteY();
Coord positie = cnt.getCoordAtPosition(x,y);
double Latt = positie.getLatitude();
double Lonn = positie.getLongitude();
nwrtetabel(Latt,Lonn);
try {

cnt.addMarker(EncodedImage.create("/maps-pin2.png"), positie , "Marker At","punt", new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Dialog.show("Marker At", "Marker At" , "OK", null);
}
});
Integer zm = 17;
cnt.zoom(new Coord(Latt, Lonn ), zm);
cnt.setShowMyLocation(true);
markerLookup.put(1,"punt");
} catch(IOException err) {
// since the image is iin the jar this is unlikely
err.printStackTrace();
}

} else if (addm == true ) {
addm = false ;
int x = evt.getX()-cnt.getAbsoluteX(); ;
int y = evt.getY()-cnt.getAbsoluteY();
Coord positie = cnt.getCoordAtPosition(x,y);
double Latt = positie.getLatitude();
double Lonn = positie.getLongitude();
nwrtetabel(Latt,Lonn);
try {

cnt.addMarker(EncodedImage.create("/maps-pin.png"), positie , "Marker At","punt", new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Dialog.show("Marker At", "Marker At" , "OK", null);
}
});
Integer zm = 17;
cnt.zoom(new Coord(Latt, Lonn ), zm);
cnt.setShowMyLocation(true);
markerLookup.put(1,"punt");
} catch(IOException err) {
// since the image is iin the jar this is unlikely
err.printStackTrace();
}
}


}
} );


hi.addComponent(BorderLayout.CENTER, Kaart );
hi.show();

}

Steve Hannah

unread,
Sep 19, 2019, 5:45:06 PM9/19/19
to codenameone...@googlegroups.com
There's the detail.

Kaart= BoxLayout.encloseYCenter(cnt);

BoxLayout.Y sizes components according to their preferred height.  Easiest to embed the MapContainer in a BorderLayout center, because that will stretch it out.  Alternatively, if you want to use a BoxLayout, you can explicitly provide a preferred size for the MapContainer using setPreferredH() and setPreferredW().

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-discu...@googlegroups.com.

Peter Bell

unread,
Sep 19, 2019, 6:32:41 PM9/19/19
to CodenameOne Discussions
Thanx Steve, that solved the problem of the small map.
Now i have a last problem. It has also to do with the googlemap. I have two forms , one with tabs and the other with the google map. In one of the tabcontainer i have button the text changes when you click on it.
it changes from start to stop. When i go to map and then go back , the button text doesnt change when you click on it . The command is executed. Do i have to give a command to repaint the button.
And how do i do that? Would be great if you have also here for an answer.
Ciao peter

Steve Hannah

unread,
Sep 19, 2019, 6:57:33 PM9/19/19
to codenameone...@googlegroups.com
You might have to repaint the button (repaint()).
But if the change of text causes the button's size to change, you may have to revalidate its parent container.  If that the parent container's size would also be caused to change, you might have to revalidate its parent.. And so on, up to the Form itself.  Try to revalidate as small a part of the UI tree as possible.

Also.  Prefer revalidateWithAnimationSafety() over plain revalidate(), as it will work nicer with running animations.

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-discu...@googlegroups.com.

Peter Bell

unread,
Sep 20, 2019, 8:16:01 AM9/20/19
to CodenameOne Discussions
Thanx steve this worked for me
Is there a way to switch between google maps and openstreet map. I tried with the openstreetmapprovider but it still shows the google maps.

Steve Hannah

unread,
Sep 20, 2019, 8:21:18 AM9/20/19
to codenameone...@googlegroups.com
MapContainer uses specifically GoogleMaps (BingMaps on UWP).  The older MapComponent can use Google maps or OSM, but it uses the image tiles API, and the user experience is not anywhere near as good.

On Fri, Sep 20, 2019 at 5:16 AM Peter Bell <pbellpi...@gmail.com> wrote:
Thanx steve this worked for me
Is there a way to switch between google maps and openstreet map. I tried with the openstreetmapprovider but it still shows the google maps.

--
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-discu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages