0

我有这个错误 java.lang.ClassCastException: [Ljava.lang.Object; 从点列表中绘制路线是我的绘图代码

公共类 MyOverlay 扩展 Overlay{

List<Double> location;
List<Double> lt;
List<Double> ln;
MapView mapView ;

Double[]lat;
Double[]lon;



public MyOverlay(List<Double> location, List<Double> lt, List<Double> ln, MapView mapView) {
    // TODO Auto-generated constructor stub
    this.location = location;
    this.mapView = mapView;
    this.ln =ln;
    this.lt = lt;
}


@Override
public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) {
    super.draw(canvas, mapView, false);

    lat = (Double[])lt.toArray();

    lon = (Double[]) ln.toArray();
    Path path1 = new Path();
    Point p1 = new Point();
    Path path2 = new Path();
    Point p2 = new Point();
    Point p3 = new Point();
    Point p4 = new Point();

    Projection projection = mapView.getProjection();
    int a = lat.length;
    int b = lon.length;
    int sum = a+b;

     Paint paint = new Paint();
     paint.setAntiAlias(true);
     paint.setColor(Color.RED);
     paint.setStyle(Paint.Style.STROKE);
     paint.setStrokeWidth(5);
     paint.setAlpha(90);

        Path p = new Path();
        Point from = new Point();
        Point to = new Point();
        for (int i = 1; i < sum; i++)
        {
            if (i == sum - 1)
            {
                break;
            }

        GeoPoint point1 =  new GeoPoint((int)(lat[i]*1E6) , (int)(lon[i]*1E6));
     (int)(Double.valueOf(lon[i+1])*1E6));
        projection.toPixels( point1, from);
        //projection.toPixels(point2, to);
        if(i ==1)
        {
        p.moveTo(from.x, from.y);
        }
        else
        {
             p.lineTo(to.x, to.y);
        }


        canvas.drawPath(p, paint);



}

} 告诉我我做错了什么?

4

1 回答 1

1

List.toArray()返回一个对象数组:Object[]. 并且 anObject[]不能转换为 a Double[]

你应该使用

lat = lt.toArray(new Double[lt.size()]);

它返回一个Double[]. 请参阅javadoc

于 2012-09-21T13:25:41.587 回答