title: How can I create a JTextField array?
body: <p>I want to add many text fields for my project and decided to just use arrays because all those 22 text fields have the same attributes.</p>
  
  <p>I had tried <code>JTextField txtFld[] = new JTextField[5];</code>. it has no parameter errors but when I try to run my program, this shows up in the console </p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  </code></pre>
  
  <p>I don't want to use </p>
  
  <pre><code>JTextField txtFld[] = new JTextField[]{
      new JTextField(10),
      ...
      ...
      ... // repeat the same code about 20 times
  };
  </code></pre>
  
  <p>Because it takes up so many lines and the text fields are of the same type anyway. All I want to do is an array of text fields with the same length and just use <code>mainPanel(txtFld[0]); ... mainPanel(txtFld[21]);</code></p>
  
  <p>Is it possible to create a text field array in just a single line of code?</p>