debugging - Android Maps NullPointerException ItemizedOverlay -
this not refer anywhere in code @ all. how go getting bottom of it?
java.lang.nullpointerexception @ com.google.android.maps.overlaybundle.draw(overlaybundle.java:42) @ com.google.android.maps.mapview.ondraw(mapview.java:494) @ android.view.view.draw(view.java:6739) @ android.view.viewgroup.drawchild(viewgroup.java:1648) @ android.view.viewgroup.dispatchdraw(viewgroup.java:1375) @ android.view.viewgroup.drawchild(viewgroup.java:1646) @ android.view.viewgroup.dispatchdraw(viewgroup.java:1375) @ android.view.view.draw(view.java:6742) @ android.widget.framelayout.draw(framelayout.java:352) @ android.view.viewgroup.drawchild(viewgroup.java:1648) @ android.view.viewgroup.dispatchdraw(viewgroup.java:1375) @ android.view.view.draw(view.java:6742) @ android.widget.framelayout.draw(framelayout.java:352) @ com.android.internal.policy.impl.phonewindow$decorview.draw(phonewindow.java:1872) @ android.view.viewroot.draw(viewroot.java:1422) @ android.view.viewroot.performtraversals(viewroot.java:1167) @ android.view.viewroot.handlemessage(viewroot.java:1744) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:144) @ android.app.activitythread.main(activitythread.java:4937) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:521) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) @ dalvik.system.nativestart.main(native method)
here draw method of itemizedoverlay
public void draw(canvas canvas, mapview mapview, boolean shadow) { try { super.draw(canvas, mapview, false); if (getmainoverlayarray().size() != 0){ pfoverlayitem tempover = null; (int = 0; < getmainoverlayarray().size(); i++) { tempover = getmainoverlayarray().get(i); boolean ismatch = false; if (tempover.gettitle().equals(selectedname)) { ismatch = true; } if (ismatch){ projection projection = mapview.getprojection(); point point = new point(); projection.topixels(tempover.getpoint(), point); paint background = new paint(); background.setcolor(color.white); background.setalpha(150); rectf rect = new rectf(); rect.set(point.x - 55, point.y +15, point.x + 100, point.y + 65); canvas.drawroundrect(rect, 5, 5, background); paint text = new paint(); text.setantialias(true); text.setcolor(color.blue); text.settextsize(14); text.settypeface(typeface.monospace); canvas.drawtext(tempover.gettitle() , point.x -50 , point.y + 30, text); canvas.drawtext(tempover.gettypetextout(), point.x -50 , point.y + 45, text); canvas.drawtext(tempover.getdestination(), point.x -50 , point.y + 60, text); } } } }catch (exception e){ log.e("error", "problem drawing view", e); e.printstacktrace(); } }
i print out stacktrace , no difference! :-(
does have ideas bottom of this?
edit - latest code 28/11 full class
private class sitesoverlay extends itemizedoverlay<pfoverlayitem> { private list<pfoverlayitem> items = new arraylist<pfoverlayitem>(); private popuppanel panel=new popuppanel(r.layout.popup); private maplocation selectedmaplocation; private static final int circleradius = 2; private arraylist<pfoverlayitem> moverlays = new arraylist<pfoverlayitem>(); public sitesoverlay() { super(null); //super(boundcenter(defaultmarker)); //items = getmainoverlayarray(); //items = moverlays; populate(); } public void finishedloading(){ populate(); } @override protected pfoverlayitem createitem(int i) { // log.i("create","marker"); return (items.get(i)); } public void additem(overlayitem overlay) { overlay.setmarker(boundcenter(overlay.getmarker(0))); items.add((pfoverlayitem) overlay); //populate(); } public void clearitems(){ runonuithread(new runnable() { public void run() { items.clear(); mymapview.invalidate(); } }); } public void clear() { moverlays.clear(); mymapview.removeallviews(); //numitems = 0; // workaround bug class: // http://groups.google.com/group/android-developers/browse_thread/thread/38b11314e34714c3 setlastfocusedindex(-1); populate(); } @override public void draw(canvas canvas, mapview mapview, boolean shadow) { super.draw(canvas, mapview, false); try { if (getmainoverlayarray().size() != 0){ pfoverlayitem tempover = null; (int = 0; < getmainoverlayarray().size(); i++) { tempover = getmainoverlayarray().get(i); boolean ismatch = false; //log.i("selected name",selectedname); if (tempover.gettitle().equals(selectedname)) { ismatch = true; } if (ismatch){ projection projection = mapview.getprojection(); point point = new point(); projection.topixels(tempover.getpoint(), point); paint background = new paint(); background.setcolor(color.white); background.setalpha(150); rectf rect = new rectf(); rect.set(point.x - 50, point.y +15, point.x + 90, point.y + 50); canvas.drawroundrect(rect, 5, 5, background); paint text = new paint(); text.setantialias(true); text.setcolor(color.blue); text.settextsize(14); text.settypeface(typeface.monospace); //canvas.drawroundrect(rect, 2, 2, background); canvas.drawtext(tempover.gettitle() + " " + tempover.getcallsign(), point.x -50 , point.y + 30, text); canvas.drawtext(tempover.getdestination() + " " + tempover.getdraft(), point.x -50 , point.y + 45, text); } } } }catch (exception e){ log.e("error", "problem drawing view", e); e.printstacktrace(); } } @override protected boolean ontap(int i) { pfoverlayitem item = getitem(i); if (selectedname.equals(item.gettitle())){ //toast.maketext(planefindermain.this, "second mofo press", 3000).show(); try{ intent myintent = new intent(planefindermain.this, detailactivity.class); myintent.putextra( "int", i); myintent.putextra( "string", selectedname ); planefindermain.this.startactivity(myintent); }catch (exception e){ log.e("error", "cannot launch", e); } } currentadshex = item.getmmsi(); new getroutetask(item.getmmsi()).execute(); selecteditem = i; selectedname = item.gettitle(); selectedplanepoint = item.getpoint(); geopoint geo=item.getpoint(); point pt=mymapview.getprojection().topixels(geo, null); view view=panel.getview(); ((textview)view.findviewbyid(r.id.reg)).settext(item.gettitle()); ((textview)view.findviewbyid(r.id.flightno)).settext(item.getcallsign()); ((textview)view.findviewbyid(r.id.route)).settext(item.getdestination()); ((textview)view.findviewbyid(r.id.height)).settext(item.getdraft()); return (true); } @override public boolean ontouchevent(motionevent event, mapview mapview) { if (event.getaction() == motionevent.action_down){ if (selectedplanepoint != null){ projection projection = mapview.getprojection(); point point = new point(); projection.topixels(selectedplanepoint, point); point pointhit = new point(); pointhit.x=(int)event.getx(); pointhit.y=(int)event.gety(); if ((point.x - pointhit.x) >-100 && (point.x - pointhit.x) <70 && (point.y - pointhit.y) < -25 && (point.y - pointhit.y) > -95){ try{ intent myintent = new intent(planefindermain.this, detailactivity.class); myintent.putextra( "int", selecteditem); myintent.putextra( "string", selectedname ); planefindermain.this.startactivity(myintent); }catch (exception e){ log.e("error", "cannot launch", e); } }else{ } } } return false; } @override public int size() { return (items.size()); } public void addoverlay(overlayitem o){ setlastfocusedindex(-1); populate(); } }
actually problem not in implementation of itemizedoverlay, in implementation of mapactivity. can see similar stack trace here @ line 42 overlaybundle calling draw() method of overlay. points null overlay added mapview somewhere.
some helpful hints: should pass drawable super constructor (used of hit-testing) uncommenting first line of code have in there:
public sitesoverlay() { //super(null); super(boundcenter(defaultmarker)); //items = getmainoverlayarray(); //items = moverlays; populate(); }
and potentially not call super.draw() in draw() method.
@override public void draw(canvas canvas, mapview mapview, boolean shadow) { // why do if paint later on. super.draw(canvas, mapview, false
most have both.
edit: come think of should pass drawable super constructor used hit-testing. amended text above reflect that.
Comments
Post a Comment