Simulator:no error
Android: crash with null point exception
iOS: crash with null pointer exception

re-using a mapobject causes a null pointer exception.   in the code below 
onRefresh() and onList() are dummy functions that simply change the icon of 
a map marker based upon user selection.  calling  mo.point.setIcon(image1); 
 results in the error because point is null;

Full code with most everything removed just enough to show the error

package com.howudodat.test.ui;

import com.codename1.googlemaps.MapContainer;
import com.codename1.googlemaps.MapContainer.MapObject;
import com.codename1.location.Location;
import com.codename1.location.LocationListener;
import com.codename1.location.LocationManager;
import com.codename1.maps.Coord;
import com.codename1.maps.MapListener;
import com.codename1.ui.Command;
import com.codename1.ui.Component;
import com.codename1.ui.Display;
import com.codename1.ui.EncodedImage;
import com.codename1.ui.FontImage;
import com.codename1.ui.Image;
import com.codename1.ui.Toolbar;
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.events.ActionListener;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;

public class FrmMap extends com.codename1.ui.Form {
protected MapContainer cnt = new MapContainer();
protected MapObject mo = null;
protected Image image0 = FontImage.createMaterial(FontImage.MATERIAL_HOME, 
UIManager.getInstance().getComponentStyle("Command"), 5);
protected Image image1 = 
FontImage.createMaterial(FontImage.MATERIAL_REFRESH, 
UIManager.getInstance().getComponentStyle("Command"), 5);
protected Image image2 = FontImage.createMaterial(FontImage.MATERIAL_LIST, 
UIManager.getInstance().getComponentStyle("Command"), 5);
    public FrmMap() {
        this(Resources.getGlobalResources());
    }
    
    public FrmMap(Resources resourceObjectInstance) {
        initManualComponents();
Display.getInstance().callSerially(() -> { 
       centerMapToLocation();
});
    }
protected void initManualComponents() {
        setLayout(new BorderLayout());
        setTitle("Map");
        setName("FrmMap");
// sidebar
if (getToolbar() == null) {
setToolbar(new Toolbar());
}
FrmSideMenu.CreateToolbar(getToolbar());

this.setScrollable(false);
        this.addComponent(BorderLayout.CENTER, cnt);
        cnt.addMapListener(new MapListener() {
@Override
public void mapPositionUpdated(Component source, int zoom, Coord center) {
}
});
        
Command cmdRefresh = new 
Command("",FontImage.createMaterial(FontImage.MATERIAL_REFRESH, 
UIManager.getInstance().getComponentStyle("Command"), 5)) {
public void actionPerformed(com.codename1.ui.events.ActionEvent ev) {
onRefresh();
}
};
Command cmdList = new 
Command("",FontImage.createMaterial(FontImage.MATERIAL_LIST, 
UIManager.getInstance().getComponentStyle("Command"), 5)) {
public void actionPerformed(com.codename1.ui.events.ActionEvent ev) {
onList();
}
};
this.getToolbar().addCommandToRightBar(cmdRefresh);
this.getToolbar().addCommandToRightBar(cmdList);
    }
protected void centerMapToLocation() {
        LocationManager l = LocationManager.getLocationManager(); 
        l.setLocationListener(new LocationListener() {
        public void locationUpdated(Location loc) {     
        Coord c = new Coord(loc.getLatitude(), loc.getLongitude());
        cnt.zoom(c , 13);
        l.setLocationListener(null);
        onMapUpdate(13, c);
        }

        public void providerStateChanged(int newState) {
        }
        }); 
}

protected void onMapUpdate(int zoom, Coord center) {
mo = cnt.addMarker(EncodedImage.createFromImage(image0, false),
center,
"test",
"test",
new ActionListener<ActionEvent>() {
public void actionPerformed(ActionEvent evt) {
onClickMap();
}
}
);
}
protected void onRefresh() {
mo.point.setIcon(image1);
repaint();
}
protected void onList() {
mo.point.setIcon(image2);
repaint();
}
protected void onClickMap() {
System.out.println("whoohoo");
}
}


-- 
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 [email protected].
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/bf1e354f-8d6b-4445-b3c9-7c3d46a26357%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to