I have a NPE Exception, while I have all declared objects:
Main class:
package com.company;
import javax.swing.*;
public class Main extends Plansza{
public static final JFrame frame = new JFrame();
public static void main(String[] args) {
frame.setLocationRelativeTo(null);
frame.add(areaPanel);
frame.setVisible(true);
frame.setBounds(0,0,800,600);
}
}
GUI class:
package com.company;
import javax.swing.*;
import java.awt.*;
public class Plansza {
int[][] area = new int[8][8];
static public JPanel areaPanel;
Figura figura = new Figura();
public Plansza(){
plansza();
}
public static void plansza(){
areaPanel = new JPanel(new GridLayout(8,8));
areaPanel.add(new JButton("PLAY"));
}
}
console log:
Exception in thread "main" java.lang.NullPointerException
at java.desktop/java.awt.Container.addImpl(Container.java:1117)
at java.desktop/java.awt.Container.add(Container.java:1029)
at java.desktop/javax.swing.JFrame.addImpl(JFrame.java:553)
at java.desktop/java.awt.Container.add(Container.java:436)
at com.company.Main.main(Main.java:7)
the at com.company.Main.main(Main.java:7)
is : frame.add(areaPanel);
Idk, should I create object panel
in Main? I wanted extend main class by Plansza
class, for more clearly code.
Where is mistake? I'll glad 4 your help, thanks :)