title: I'm trying to make chart with a string of number but if I try to repaint my paintComponent(Graphics g) method won't be called
body: <p>I'm trying to make chart with a string of number but if I try to repaint my paintComponent(Graphics g) method won't be called. I debugged the file and i really don't understand why this happens. This class extends JPanel and the method: "verwerkData(String s)" is called when I press a button on my JFrame.</p>
  
  <p>Try-catch is used because when I start the program paintComponent(Graphics g) is called and "punt" and "punti" aren't initialized yet that's why i throw a NullPointerException.</p>
  
  <pre><code>package grafiek;
  
  import java.awt.Graphics;
  
  public class Grafiek extends javax.swing.JPanel {
  
  private String[] punt;
  private int[] punti;
  private int afstandX, afstandY, puntX1=0, puntY1=0, puntX2=0, puntY2=0;
  private int max=0;
  
  /**
   * Creates new form Grafiek
   */
  public Grafiek() {
      initComponents();
  }
  
  @Override
  public void paintComponent(Graphics g) {
  
      try{
          for(int i=0; i&lt;punti.length; i++) {
              if(max &gt;= punti[i]) {
                  max = punti[i];
              }
          }
  
          afstandX = getWidth()/punt.length;
          afstandY = getHeight()/max;
  
          for(int i=0; i&lt;punti.length; i++) {
              puntX1 = puntX2;
              puntY1 = puntY2;
              puntX2 += afstandX;
              puntY2 = punti[i]*afstandY;
  
              System.out.println(puntX1+" "+puntY1+" "+puntX2+" "+puntY2);
  
              g.drawLine(puntX1, puntY1, puntX2, puntY2);
          }
      }catch(java.lang.NullPointerException npe) {
          super.paintComponent(g);
      }
  }
  
  public void verwerkData(String s) {
      punt = s.split(" ");
  
      punti = new int[punt.length];
  
      for(int i=0; i&lt;punt.length; i++) {
          punti[i] = Integer.parseInt(punt[i]);
      }
  
      repaint();
  }
  
  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
  private void initComponents() {
  
      setBackground(new java.awt.Color(204, 204, 204));
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
      this.setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGap(0, 400, Short.MAX_VALUE)
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGap(0, 300, Short.MAX_VALUE)
      );
  }// &lt;/editor-fold&gt;                        
  
  }
  </code></pre>