I have initialized paint now. The nullpointerexception is solved by
this. But i still can't see any line on the map. As you said I have to
attach the canvas to the view or so. I have read the links you
supplied. But I dont understand it. I need to use the MapView and draw
lines on it. How can i do this. Could you please show me in a simple
way how i can do this?

thank you

On Jun 21, 4:55 am, Marco Nelissen <marc...@android.com> wrote:
> The problem is those last two lines:    canvas = new Canvas();
>     canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);
>
> That creates a new Canvas, then draws in to it. The problem with that is
> that the Canvas isn't "attached" to anything, so you're essentially drawing
> in to something that is not visible.
> You should probably have a look 
> at:http://developer.android.com/reference/android/view/View.html#onDraw(...)
>
> On Sat, Jun 20, 2009 at 7:14 PM, nEx.Software 
> <justin.shapc...@gmail.com>wrote:
>
>
>
> > In your code, I am not seeing anywhere that you have initialized
> > paint. That would be the first place I'd look.
>
> > On Jun 20, 5:50 pm, mnish <twan...@gmail.com> wrote:
> > > Hello,
> > > I have a problem with drawing lines between two points on google map.
> > > I get nullpointerexception on this line of code:
> > > canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);
>
> > > I know this is a very basic thing, but I don't know not much about it
> > > and I really really need your help.
>
> > >  here is were i call this method:
>
> > >         @Override
> > >         public void onCreate(Bundle savedInstanceState) {
> > >                 super.onCreate(savedInstanceState);
> > >                 setContentView(R.layout.main);
>
> > >                 linearLayout = (LinearLayout)
> > findViewById(R.id.zoomview);
> > >                 mapView = (MapView) findViewById(R.id.mapview);
> > >                 mapView.setBuiltInZoomControls(on);
> > >                 mapOverlays = mapView.getOverlays();
> > >                 drawable =
> > this.getResources().getDrawable(R.drawable.circle);
> > >                 itemizedoverlay = new HelloItemizedOverlay(drawable);
> > >                 Projection projection = mapView.getProjection();
>
> > >                 Double lat1 = 30.342833*1E6, lon1 = -91.719033*1E6;
> > >                 Double lat2 = -37.5262180*1E6, lon2 = 175.8060710*1E6;
> > >                 point1 = new GeoPoint(lat1.intValue(), lon1.intValue());
> > >                 point2 = new GeoPoint(lat2.intValue(), lon2.intValue());
> > >                 p1 = new Point();
> > >                 p2 = new Point();
> > >                 projection.toPixels(point1, p1);
> > >                 projection.toPixels(point2, p2);
> > >                 canvas = new Canvas();
> > >                 canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);
>
> > >         }
>
> > > Any help is more than welcome.
--~--~---------~--~----~------------~-------~--~----~
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