I'm trying to make an array of jpanels
but I got some null pointer exception
.
here is the part of the code. The cartP
here is a panel
.
JPanel[] p2 = new JPanel[10];
p2[0].setPreferredSize(new Dimension(700, 40));
p2[0].setMaximumSize(p2[0].getPreferredSize());
p2[0].setLayout(new GridLayout(1,5,1,1));
p2[0].add(new JLabel("text"));
p2[0].add(new JLabel("text"));
p2[0].add(new JLabel("text"));
p2[0].add(new JLabel("text"));
p2[0].setBackground(Color.CYAN);
cartP.add(p2[0]);
I'll use it for making a view cart just like on the shopping website.
here is the exception..
Exception in thread "main" java.lang.NullPointerException
at storeapp.Cart.gui(Cart.java:59)
at storeapp.Cart.<init>(Cart.java:29)
at storeapp.Cart.main(Cart.java:157)
Java Result: 1
Any idea why i get that exception?