I want to create a shape with mulitple sides using Lang.Math and GeneralPath in Java GUI. I was able to transfer the value of ne(the number of sides) from Fenster to my class but the code isnt working. ik the code for the shape is right because it was same code i used for hexagon. i think the problem might be that the number sides is in variable form(because if i change the variable with a number it seems to work) but idk how to fix it. it is showing the following error Exception in thread "AWT-EventQueue-0" "java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 at Neck.genneck(Neck.java:30) at Zeichnung.paintComponent(Zeichnung.java:104)" Please help me
**this is the code **
import javax.swing.*;
import java.awt.geom.GeneralPath;
public class Neck extends Form {
int r;
private int ne ;
private double[] px, py;
public Neck(int x, int y, int r) {
super(x,y);
this.r=r;
px=new double[ne];
py=new double[ne];
}
public void seiten (int ne) {
this.ne=ne;
}
public Shape genneck() {
for(int i = 0; i<ne; i++) {
px[i]=x+(r*Math.sin(Math.toRadians(i*360/ne)));
py[i]=y-(r*Math.sin(Math.toRadians(i*360/ne)));
}
GeneralPath path = new GeneralPath(GeneralPath.WIND_NON_ZERO);
path.moveTo(px[0],py[0]);
for(int i = 1; i<ne; i++) {
path.lineTo(px[i],py[i]);
}
path.closePath();
return path;
}
}