title: Bezier curve in Java with Points
body: <p>I'm trying to make a simple program that will draw a Curve through randomly generated points.But something goes wrong and the compiler gives an error.I'm just starting to learn java and this is one of the first tasks. I hope you can point out my mistakes. Here is the code</p>
  
  <pre><code>public class Framey {
  
  private static int fact(int n) {
      int fact = 1;
      for(int i = 1; i &lt;= n;i++) {
          fact *= i;
      }
      return fact;
  }
  
  private static double bernstein(float t,int n,int i) {
      return (fact(n)/(fact(i)*fact(n-i)))*Math.pow(1-t, n-i)*Math.pow(t, i);
  }
  
  
  private JFrame frame;
  
  
  
  /**
   * Launch the application.
   */
  public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
          public void run() {
              try {
                  Framey window = new Framey();
                  window.frame.setVisible(true);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      });
  }
  
  /**
   * Create the application.
   */
  public Framey() {
      initialize();
  
  }
  
  /**
   * Initialize the contents of the frame.
   */
  private void initialize() {
      frame = new JFrame();
      frame.setBounds(100, 100, 450, 300);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.getContentPane().setLayout(null);
  
      JPanel panel = new JPanel();
      panel.setBackground(Color.LIGHT_GRAY);
      panel.setBounds(23, 35, 250, 200);
      frame.getContentPane().add(panel);
  
  
      JSpinner spinner = new JSpinner();
      spinner.setBounds(291, 113, 30, 20);
      frame.getContentPane().add(spinner);
  
      JLabel warning = new JLabel("Value cannot be larger than 8!");
      warning.setFont(new Font("Tahoma", Font.BOLD, 9));
      warning.setBounds(283, 144, 141, 53);
      frame.getContentPane().add(warning);
      warning.setVisible(false);
  
      JButton btnNewButton = new JButton("New button");
      btnNewButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              int pointCount;
  
              pointCount = (int) spinner.getValue();
              if (pointCount&gt;8) {
                  warning.setVisible(true);
              }else {warning.setVisible(false);}
  
  
  
  
              Point[] points = getPoints(pointCount); 
  
               drawScene(points);
          }
          private  Point[] getPoints(int pointCount) {
              Random val = new Random();
              Point[] points = new Point[pointCount];
              for(int i=0;i&lt;pointCount;i++) {
                  points[i].x = val.nextInt(panel.getWidth());
                  points[i].y =val.nextInt(panel.getHeight());
              }
              return points;
          }
          private void drawScene(Point[] points) {
              int pWidth = panel.getWidth();
              int pHeight = panel.getHeight();
              Graphics g = panel.getGraphics();
              int pointCount = points.length;
              g.setColor(Color.WHITE);
              g.fillRect(0,0, pWidth, pHeight);
  
              if(pointCount&gt;1) {
                  float t = 0;
                  while( t&lt;=1) {
                      g.setColor(Color.DARK_GRAY);
                      besierCurve(t, points);
                      t+=0.001;
                  }
              }
          };
  
  
          private void besierCurve(float t , Point[] points) {
  
              Graphics g = panel.getGraphics();
              int pointCount = points.length; 
              double bPoly[] = new double[pointCount];
              for(int i =0;i&lt;pointCount;i++) {
                  bPoly[i] = bernstein(t,pointCount-1,i+1);
              }
  
              double sumX = 0;
              double sumY = 0;
              for(int i=0;i&lt;pointCount;i++) {
                  sumX += bPoly[i] * points[i].x;
                  sumY += bPoly[i] * points[i].y;
              }
  
              int x , y;
              x=(int) Math.round(sumX);
              y=(int) Math.round(sumY);
              g.drawLine(x, y, x, y);
  
          }
  
  
  
  
  
  
      });
  </code></pre>
  
  <p>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at bezjeLiikne.Framey$2.getPoints(Framey.java:106) at bezjeLiikne.Framey$2.actionPerformed(Framey.java:98) </p>