Hallo, ich habe das Problem, dass folgende Exception beim Ausführen meines Programmes kommt:
Exception in thread "main" java.lang.NullPointerException
at main.Window.<init>(Window.java:49)
at main.Main.startWindow(Main.java:21)
at main.Main.main(Main.java:28)
Ich habe schon versucht, den Fehler selbstständig zu finden, aber nichts gefunden.
Hier ist der Code:
[CODE lang="java" title="Main Klasse"]package main;
import javax.swing.JFrame;
public class Main {
public static JFrame frame;
public static final int WIDTH = 700;
public static final int HEIGHT = 700;
public static final String NAME = "Unbekanntes Projekt - 0.1";
public static boolean isRunning = false;
public Window window;
public void startWindow() {
window = new Window();
window.setVisible(true);
}
public static void main(String[] args) {
isRunning = true;
Main main = new Main();
main.startWindow();
}
}
[/CODE]
Und hier ist die zweite Klasse:
LG
Exception in thread "main" java.lang.NullPointerException
at main.Window.<init>(Window.java:49)
at main.Main.startWindow(Main.java:21)
at main.Main.main(Main.java:28)
Ich habe schon versucht, den Fehler selbstständig zu finden, aber nichts gefunden.
Hier ist der Code:
[CODE lang="java" title="Main Klasse"]package main;
import javax.swing.JFrame;
public class Main {
public static JFrame frame;
public static final int WIDTH = 700;
public static final int HEIGHT = 700;
public static final String NAME = "Unbekanntes Projekt - 0.1";
public static boolean isRunning = false;
public Window window;
public void startWindow() {
window = new Window();
window.setVisible(true);
}
public static void main(String[] args) {
isRunning = true;
Main main = new Main();
main.startWindow();
}
}
[/CODE]
Und hier ist die zweite Klasse:
Java:
package main;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Window extends JFrame implements ActionListener {
public static final JPanel mainpanel = new JPanel();
public static final JPanel upperpanel = new JPanel();
public static final JPanel lowerpanel = new JPanel();
public static JLabel TITLE;
public static JTextField TEXT;
public static JTextField DIALOG;
public static JButton dialogAuswahlA;
public static JButton dialogAuswahlB;
public static JButton INVENTORY;
public static JButton ERKUNDEN;
public static final Font fontNormal = new Font("Arial", 0, 20);
public static final Font fontFett = new Font("Arial", 0, 30);
public static final Color backgroundColor = new Color(128,186,195);
public Window() {
setTitle(Main.NAME);
setSize(Main.WIDTH, Main.HEIGHT);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainpanel.setBackground(backgroundColor);
add(mainpanel);
upperpanel.setBackground(Color.gray);
add(upperpanel, BorderLayout.NORTH);
lowerpanel.setBackground(Color.gray);
add(lowerpanel, BorderLayout.SOUTH);
TITLE.setText("Hauptmenü");
TITLE.setFont(fontFett);
upperpanel.add(TITLE);
}
public void actionPerformed(ActionEvent e) {
}
}
LG