title: how can I create an alert dialog box in a subclass of the main class in android?
body: <p>I have a main class which extends MapActivity and I'm going to create alert dialog in a subclass, but I encountered an error of Context parameter.
  here is my java code:</p>
  
  <p>public class main extends MapActivity {</p>
  
  <pre><code>private MapView mapView;
  private MapController mapController;
  private GeoPoint geopoint;
  
  public class MapOverlay extends Overlay {
  
      @Override
      public boolean onTouchEvent(MotionEvent event, MapView mapv){
  
          if(event.getAction()==1){
              GeoPoint p = mapv.getProjection().fromPixels(
                      (int) event.getX(), 
                      (int) event.getY());
              Toast.makeText(getBaseContext(), "Location: " + 
                      p.getLatitudeE6()/1E6 + "," +
                      p.getLongitudeE6()/1E6, Toast.LENGTH_LONG).show();
              AlertDialog ad = new AlertDialog.Builder(this).create();    
              ad.setCancelable(false); // This blocks the 'BACK' button  
              ad.setMessage("Hello World");  
              ad.setButton("OK", new DialogInterface.OnClickListener() {  
                  @Override  
                  public void onClick(DialogInterface dialog, int which) {  
                      dialog.dismiss();                      
                  }  
              });  
              ad.show(); 
          }
          return false;
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The error is:</p>
  
  <blockquote>
    <p>The constructor AlertDialog.Builder(main.MapOverlay) is undefined!</p>
  </blockquote>
  
  <p>I changed this to <code>getBaseContext()</code>, but I encountered Force Close error.</p>