I want to create a new DWG file using Aspose.CAD and then write a graphic into it. However, the following code always throws an error ‘java.lang.ArrayIndexOutOfBoundsException: 0’. How can I solve this?
@Test
public void a(){
CadImage image = new CadImage();
List<Cad2DPoint> cadPoints = new ArrayList<>();
Cad2DPoint point = new Cad2DPoint();
point.setX(-5d);
point.setY(-5d);
cadPoints.add(point);
Cad2DPoint point2 = new Cad2DPoint();
point2.setX(-5d);
point2.setY(10d);
cadPoints.add(point2);
Cad2DPoint point3 = new Cad2DPoint();
point3.setX(20d);
point3.setY(10d);
cadPoints.add(point3);
Cad2DPoint point4 = new Cad2DPoint();
point4.setX(20d);
point4.setY(-5d);
cadPoints.add(point4);
CadLwPolyline cadPolyline = new CadLwPolyline();
cadPolyline.setCoordinates(cadPoints);
cadPolyline.setFlag(CadLwPolylineFlag.Closed);
cadPolyline.setConstantWidth(0.1);
List<CadBaseEntity> entities = new ArrayList<>();
entities.add(cadPolyline);
image.setEntities(ArrayUtil.toArray(entities, CadBaseEntity.class));
image.updateSize();
image.save("C:\\Users\\BDAndroid\\Desktop\\Drawing1.dwg",false);
}