While creating the object of your class helloItemizedOverlay you are
supposed to pass the current context. Use the constructor
helloItemizedOverlay(Drawable defaultMarker, Context context). When
you do this your context will not be null.
This constructor in turn is calling the super constructor.

Thanks

On Sep 13, 4:50 pm, Logesh rajendren <loges...@gmail.com> wrote:
> you have only one activity in your manifest file . include the
> HelloItemizedOverlay activity in your manifest file.
>
>
>
>
>
>
>
> On Mon, Sep 12, 2011 at 12:30 AM, rochi <pruebaenvioj...@gmail.com> wrote:
> > hello, I'm having problems with this code:
>
> >http://developer.android.com/resources/tutorials/views/hello-mapview....
>
> > In main.xml I have:
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
> > android"
> >    android:id="@+id/mainlayout"
> >    android:orientation="vertical"
> >    android:layout_width="fill_parent"
> >    android:layout_height="fill_parent" >
>
> >  <com.google.android.maps.MapView
> >        android:id="@+id/mapview"
> >        android:layout_width="fill_parent"
> >        android:layout_height="fill_parent"
> >        android:clickable="true"
> >        android:apiKey="myKey"
> >    />
>
> > </RelativeLayout>
>
> > In the AndroidManifest.xml
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <manifest xmlns:android="http://schemas.android.com/apk/res/android";
> >      package="maps.rochi"
> >      android:versionCode="1"
> >      android:versionName="1.0">
> >    <uses-sdk android:minSdkVersion="13" />
>
> >    <uses-permission android:name="android.permission.INTERNET" />
>
> >    <application android:icon="@drawable/icon" android:label="@string/
> > app_name">
>
> >        <uses-library android:name="com.google.android.maps" />
>
> >        <activity android:name=".MapsActivity"
> >                  android:label="@string/app_name">
> >            <intent-filter>
> >                <action android:name="android.intent.action.MAIN" />
> >                <category
> > android:name="android.intent.category.LAUNCHER" />
> >            </intent-filter>
> >        </activity>
>
> >    </application>
>
> > </manifest>
>
> > In mapsActivity.java:
>
> > public class MapsActivity extends MapActivity {
>
> >        LinearLayout linearLayout;
> >        MapView mapView;
> >        MapController mapController;
>
> >        List<Overlay> mapOverlays;
> >        Drawable drawable;
> >        helloItemizedOverlay itemizedOverlay;
>
> >    protected boolean isRouteDisplayed() {
> >        return false;
> >    }
>
> >    /** Called when the activity is first created. */
> >    @Override
> >    public void onCreate(Bundle savedInstanceState) {
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.main);
>
> >        mapView = (MapView) findViewById(R.id.mapview);
> >        mapView.setBuiltInZoomControls(true);
>
> >        mapController = mapView.getController();
>
> >        mapOverlays = mapView.getOverlays();
> >        drawable =
> > this.getResources().getDrawable(R.drawable.bikeicon);
> >        itemizedOverlay = new helloItemizedOverlay(drawable);
>
> >        GeoPoint point = new GeoPoint(19240000,-99120000);
> >        OverlayItem overlayitem = new OverlayItem(point, "Hola,
> > Mundo!", "I'm in Mexico City!");
>
> >        itemizedOverlay.addOverlay(overlayitem);
>
> >        mapOverlays.add(itemizedOverlay);
>
> >    }
> > }
>
> > And helloItemizedOverlay:
>
> > public class helloItemizedOverlay extends ItemizedOverlay {
>
> >    Context mContext = null;
> >    private ArrayList<OverlayItem> mOverlays = new
> > ArrayList<OverlayItem>();
>
> >    public helloItemizedOverlay(Drawable marker) {
> >        super(boundCenterBottom(marker));
>
> >    }
>
> >        public void addOverlay(OverlayItem overlay) {
> >            mOverlays.add(overlay);
> >            populate();
> >        }
>
> >        @Override
> >        protected OverlayItem createItem(int i) {
> >          return mOverlays.get(i);
> >        }
>
> >        @Override
> >        public int size() {
> >                // TODO Auto-generated method stub
> >                return mOverlays.size();
> >        }
>
> >    public helloItemizedOverlay(Drawable defaultMarker, Context
> > context) {
> >        super(defaultMarker);
> >        mContext = context;
> >    }
>
> >        @Override
> >        protected boolean onTap(int index){
> >                  OverlayItem item = mOverlays.get(index);
> >                  try{
> >                          AlertDialog.Builder dialog = new
> > AlertDialog.Builder(mContext);
> >                          dialog.setTitle(item.getTitle());
> >                          dialog.setMessage(item.getSnippet());
> >                          dialog.show();
> >                  } catch (Exception e){
> >                          e.printStackTrace();
> >                  }
>
> >                  return true;
> >        }
>
> > }
>
> > When I click in some icon, I found a nullPointerException in  this
> > line AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
>
> > what's my mistake???
>
> > Thank you so much!
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to