Problem with MapContainer

66 views
Skip to first unread message

jeremy.te...@gmail.com

unread,
Feb 4, 2017, 3:46:56 PM2/4/17
to CodenameOne Discussions
Hello I have a Problem with the MapContainer component on Android:

If I open my screen I get following error message:

"An internal application error occurred java.lang.NullPointerException: Attempt to invoke virtual methode 'int java.io.InputStream.read(byte[]) on a null object reference"

I use following Code

        Form l_form = new Form("Google Maps");
        l_form
.setLayout(new BorderLayout());
       
       
final MapContainer l_map = new MapContainer();
       
final Label l_label = new Label("Location: ...");
       
       
try {
            l_map
.addMarker(EncodedImage.create("maps-pin.png"), new Coord(41.889, -87.622), "Hi marker", "Hello", new ActionListener() {
               
public void actionPerformed(ActionEvent evt) {
                   
Dialog.show("Marker Clicked!", "You clicked the marker", "OK", null);
               
}
           
});
       
} catch (IOException e) {
            e
.printStackTrace();
       
}
       
        l_map
.addMapListener(new MapListener() {
           
public void mapPositionUpdated(Component source, int zoom, Coord center) {
                l_label
.setText("0 lon: " + l_map.getCoordAtPosition(0, 0).getLongitude()+ " w lon " + l_map.getCoordAtPosition(Display.getInstance().getDisplayWidth(), 0).getLongitude());
           
}
       
});
       
        l_form
.addComponent(BorderLayout.SOUTH, l_label);
        l_form
.addComponent(BorderLayout.CENTER, l_map);
       
        addSidebar
(l_form);  
        g_current
= l_form;
        l_form
.show();



Shai Almog

unread,
Feb 5, 2017, 1:10:42 AM2/5/17
to CodenameOne Discussions, jeremy.te...@gmail.com
Hi,
that means there is a null pointer exception somewhere where a null input stream is passed but it's hard to tell where (probably not in this code block).
Connect your device using a cable and use DDMS/logcat to look at the output from the device to see the stack trace in question.

jeremy.te...@gmail.com

unread,
Feb 5, 2017, 11:34:34 AM2/5/17
to CodenameOne Discussions, jeremy.te...@gmail.com

Ah Thanks, I found the problem. I used Android Studio for debugging. The problem was, that the api - key was an old one.




02-05 17:30:23.467 22331-22405/? E/b: Authentication failed on the server.
02-05
 
17:30:23.467 22331-22405/? E/Google Maps Android API: Authorization
failure
.  Please see
https
://developers.google.com/maps/documentation/android-api/start for
how to correctly
set up the map.
02-05 17:30:23.477 22331-22405/?
E
/Google Maps Android API: In the Google Developer Console
(https://console.developers.google.com)
                                                           
Ensure that the "Google Maps Android API v2" is enabled.
                                                           
Ensure that the following Android Key exists:
                                                                API
Key: --------------------------------------------------
                                                           
     
Android Application
(<cert_fingerprint>;<package_name>):



Reply all
Reply to author
Forward
0 new messages