I have the following code:
if(prevPoint != null){
Log.i("tracking class", "prevPoint: "+ prevPoint);
Point pointb = null;
Projection projection2 = mapView.getProjection();
projection2.toPixels(prevPoint, pointb);
Log.i("tracking class", "Pointb: "+ pointb);
Paint paint;
paint = new Paint();
paint.setColor(Color.BLUE);
paint.setAntiAlias(true);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(2);
Log.i("tracking class", "Point x: "+ point.x);
Log.i("tracking class", "Point y: "+ point.y);
Log.i("tracking class", "Pointb x: "+ pointb.x);
Log.i("tracking class", "Pointb y: "+ pointb.y);
//canvas.drawLine(pointb.x, pointb.y, point.x, point.y, paint);
}
The log returns this:
10-19 08:55:25.505: INFO/tracking class(29970): prevPoint: 41310173,-105558377
10-19 08:55:25.505: INFO/tracking class(29970): Pointb: null
Any thoughts why Pointb is coming back null?
Are you expecting Java to use pass by reference? It doesn’t. It uses pass by value everywhere, although the value of any expression of a reference type is a reference.
Calling
cannot possibly change the value of
pointb. You’ll need to use an assignment operator, e.g.I believe
toPixelschanges the content of the existing object referred to by the argument, if the argument is non-null… but it can’t possibly change the value of the variable to refer to a new object.