android - ItemizedOverlay Issues (HelloMapView Tutorial) -


i having trouble hello map views tutorial android developer website: http://developer.android.com/resources/tutorials/views/hello-mapview.html

my first problem upon clicking overlay item, application crash. problem solved making sure pass context itemizedoverlay class created...

after fixed problem, icon overlay not display in map. able click on map overlay located , dialog box displays. unfortunately, cannot see icon. have made sure image reference object located in r.java resources file. in fact exact problem asked poster of following thread after going through same issues. unfortunately second question never answered. context null pointer

here mapview class:

package com.mapsexample;  import java.util.list;  import android.content.context; import android.graphics.drawable.drawable; import android.os.bundle;  import com.google.android.maps.geopoint; import com.google.android.maps.mapactivity; import com.google.android.maps.mapview; import com.google.android.maps.overlay; import com.google.android.maps.overlayitem;  public class hellomaps extends mapactivity {     /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         mapview mapview = (mapview) findviewbyid(r.id.mapview);         mapview.setbuiltinzoomcontrols(true);         list<overlay> mapoverlays = mapview.getoverlays();         drawable drawable = this.getresources().getdrawable(r.drawable.androidmarker);         helloitemizedoverlay itemizedoverlay = new helloitemizedoverlay(drawable, this);         geopoint point = new geopoint(19240000,-99120000);         overlayitem overlayitem = new overlayitem(point, "hola, mundo!", "i'm in mexico city!");         itemizedoverlay.addoverlay(overlayitem);         mapoverlays.add(itemizedoverlay);     }      @override     protected boolean isroutedisplayed() {         return false;     } } 

and itemizedoverlay class:

package com.mapsexample; import java.util.arraylist;  import android.app.alertdialog; import android.content.context; import android.graphics.drawable.drawable;  import com.google.android.maps.itemizedoverlay; import com.google.android.maps.overlayitem;   public class helloitemizedoverlay extends itemizedoverlay {   private arraylist<overlayitem> moverlays = new arraylist<overlayitem>();  context mcontext;    public helloitemizedoverlay(drawable defaultmarker) {    super(boundcenterbottom(defaultmarker));  }   public helloitemizedoverlay(drawable defaultmarker, context context) {   super(defaultmarker);   mcontext = context;  }   public void addoverlay(overlayitem overlay) {      moverlays.add(overlay);      populate();  }   @override  protected overlayitem createitem(int i) {    return moverlays.get(i);  }   @override  public int size() {    return moverlays.size();  }   @override  protected boolean ontap(int index) {    overlayitem item = moverlays.get(index);    alertdialog.builder dialog = new alertdialog.builder(mcontext);    dialog.settitle(item.gettitle());    dialog.setmessage(item.getsnippet());    dialog.show();    return true;  }  } 

again, if not pass 'this' itemizedoverlay constructor, icon displays cannot clicked. appreciated. in advance!

change super call in second constructor to:

super(boundcenterbottom(defaultmarker));

that should work!


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -