Hello. Here I try to deal with arrays. The idea is to create a cycle of 10 buttons, and place them on the panel. Buttons are stored in an array. On startup, knocks out a NullPointerException. Help me to understand)
package trening; import java.awt.BorderLayout; import java.awt.GridLayout; import javax.swing.*; public class massiv { JPanel window; JButton squares []; JPanel p1; massiv () { p1 = new JPanel(); squares = new JButton [10]; for (int i=0; i<10; i++) { squares[i] = new JButton(); squares[i].setVisible (true); p1.setLayout(new GridLayout (4,3)); p1.add(squares[i]); } window.setLayout(new BorderLayout()); window.add("North", p1); JFrame frame = new JFrame("massiv"); frame.setContentPane(window); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { // TODO Auto-generated method stub massiv mas = new massiv(); } }