android - onTap on map-marker give me NullPointerException -
having problem ontap on markers in google map.
this error
05-31 21:46:21.420: e/androidruntime(5541): java.lang.nullpointerexception 05-31 21:46:21.420: e/androidruntime(5541): @ com.android.internal.app.alertcontroller$alertparams.(alertcontroller.java:753) 05-31 21:46:21.420: e/androidruntime(5541): @ android.app.alertdialog$builder.(alertdialog.java:273) 05-31 21:46:21.420: e/androidruntime(5541): @ my.class.hellomapview$locationoverlay.ontap(hellomapview.java:1361)
and code error @ my.class.hellomapview$locationoverlay.ontap(hellomapview.java:1361)
public class locationoverlay extends itemizedoverlay<overlayitem> { //public class locationoverlay extends itemizedoverlay{ private arraylist<overlayitem> overlaylist = new arraylist<overlayitem>(); private mapview mapview; public string pickedlat; public string pickedlng; private context mcontext; public locationoverlay(mapview mapview, drawable defaultmarker, context context) { //super(null); super(boundcenterbottom(defaultmarker)); mcontext = context; this.mapview = mapview; // need ontap populate(); } @override protected overlayitem createitem(int i) { return overlaylist.get(i); } @override public int size() { return overlaylist.size(); } public void addoverlayitem(overlayitem overlayitem) { if(!overlaylist.contains(overlayitem)){ overlaylist.add(overlayitem); setlastfocusedindex(-1); populate(); } // populate(); } @override protected boolean ontap(int pindex) { overlayitem item = overlaylist.get(pindex); alertdialog.builder dialog = new alertdialog.builder(mcontext); dialog.settitle(item.gettitle()); dialog.setmessage(item.getsnippet()); dialog.show(); return true; } the line refered in errorlog this
alertdialog.builder dialog = new alertdialog.builder(mcontext);
and can guess googling it, mcontext not passed along... cant right...
please help
check call constructor null value might passed in there. can use this keyword since activity subclass of context so
locationoverlay locationoverlay = new locationoverlay(mapview, getresources().getdrawable(r.drawable.polis), this); or if calling fragment use getactivity() method
locationoverlay locationoverlay = new locationoverlay(mapview, getresources().getdrawable(r.drawable.polis), this.getactivity());
Comments
Post a Comment