我正在
线程“main”java.lang.NullPointerException中的异常 在deneme2.MainFrame。(MainFrame.java:43) 在deneme2.deneme2.main(deneme2.java:88) C:\ Users \ Melih \ AppData \ Local \ NetBeans \ Cache \ 8.1 \ executor-snippets \ run.xml:53:Java返回:1 建筑失败(总时间:1秒)
我有两个类用于框架,另一个用于代码,到目前为止我已经完成了大部分工作,但是我得到了这个错误。但是在我的deneme2类中,如果我删除MainFrame frame = new MainFrame();它似乎工作。
这是我的denem2课程
public class deneme2扩展了JFrame {
public static interface MessageOutput {
void appendMessage(String message);
}
private MessageOutput msgOutput = new MessageOutput() {
@Override
public void appendMessage(String message) {
System.out.println(message);
}
};
public void setMessageOutput(MessageOutput value) {
msgOutput = value;
}
private Node front, rear;
private int currentSize;
private class Node {
int data;
Node next;
}
public deneme2() {
front = null;
rear = null;
currentSize = 0;
}
public boolean isEmpty() {
return (currentSize == 0);
}
public int dequeue() {
int data = front.data;
front = front.next;
if (isEmpty()) {
rear = null;
}
currentSize--;
msgOutput.appendMessage(data + " removed from the queue");
return data;
}
public void enqueue(int data) {
Node oldRear = rear;
rear = new Node();
rear.data = data;
rear.next = null;
if (isEmpty()) {
front = rear;
} else {
oldRear.next = rear;
}
currentSize++;
System.out.println(data + " added to the queue");
}
public static void main(String a[]) throws FileNotFoundException {
MainFrame frame = new MainFrame();
queue.setMessageOutput(frame);
Scanner s = new Scanner(new File("list.txt"));
deneme2 queue = new deneme2();
while (s.hasNext()) {
queue.enqueue(s.nextInt());
}
s.close();
queue.dequeue();
}}
这是我的MainFrame类
public class MainFrame extends JFrame implements deneme2.MessageOutput {
private JTextArea txt1;
@Override
public void appendMessage(String message) {
txt1.append(message);
}
public MainFrame() {
JFrame frame = new JFrame();
JButton b1 = new JButton("Load Up the Que");
JButton b2 = new JButton("Add to the Que");
JTextArea txt2 = new JTextArea();
txt1.setEditable(false);
b1.setBounds(50, 100, 180, 100);
b2.setBounds(50, 300, 180, 100);
txt1.setBounds(600, 100, 300, 600);
txt2.setBounds(300, 300, 180, 100);
frame.add(b1);
frame.add(b2);
frame.add(txt1);
frame.add(txt2);
frame.setLayout(null);
frame.setSize(1000, 1500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}}