Help: canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Help: canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);

Postby mnish » Sun Jun 21, 2009 2:03 am

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:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         @Override
  3.  
  4.         public void onCreate(Bundle savedInstanceState) {
  5.  
  6.                 super.onCreate(savedInstanceState);
  7.  
  8.                 setContentView(R.layout.main);
  9.  
  10.  
  11.  
  12.                 linearLayout = (LinearLayout) findViewById(R.id.zoomview);
  13.  
  14.                 mapView = (MapView) findViewById(R.id.mapview);
  15.  
  16.                 mapView.setBuiltInZoomControls(on);
  17.  
  18.                 mapOverlays = mapView.getOverlays();
  19.  
  20.                 drawable = this.getResources().getDrawable(R.drawable.circle);
  21.  
  22.                 itemizedoverlay = new HelloItemizedOverlay(drawable);
  23.  
  24.                 Projection projection = mapView.getProjection();
  25.  
  26.  
  27.  
  28.                 Double lat1 = 30.342833*1E6, lon1 = -91.719033*1E6;
  29.  
  30.                 Double lat2 = -37.5262180*1E6, lon2 = 175.8060710*1E6;
  31.  
  32.                 point1 = new GeoPoint(lat1.intValue(), lon1.intValue());
  33.  
  34.                 point2 = new GeoPoint(lat2.intValue(), lon2.intValue());
  35.  
  36.                 p1 = new Point();
  37.  
  38.                 p2 = new Point();
  39.  
  40.                 projection.toPixels(point1, p1);
  41.  
  42.                 projection.toPixels(point2, p2);
  43.  
  44.                 canvas = new Canvas();
  45.  
  46.                 canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);
  47.  
  48.  
  49.  
  50.         }.
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Please tell me what do i do wrong.
Any help is more than welcome
mnish
Freshman
Freshman
 
Posts: 3
Joined: Sun Jun 21, 2009 1:57 am

Top

Postby WarrenFaith » Sun Jun 21, 2009 10:58 am

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. canvas = new Canvas();
  2.  
  3. canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

This is not possible in a Activity. You can only draw inside a View.
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby mnish » Sun Jun 21, 2009 1:42 pm

WarrenFaith wrote:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. canvas = new Canvas();
  2. canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

This is not possible in a Activity. You can only draw inside a View.


Thanks for your reply. 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
mnish
Freshman
Freshman
 
Posts: 3
Joined: Sun Jun 21, 2009 1:57 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 5 guests