java.lang.Error exception generated on line number which has nothing (blank line) !!!
This is the code :
package Components;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Interface {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame;
JPanel text = new JPanel();
JPanel controlPanel = new JPanel();
JLabel digits = new JLabel("");
frame = new JFrame("Calculator");
frame.setLayout(new FlowLayout());
frame.setPreferredSize(new Dimension(300, 400));
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
System.exit(0);
}
});
frame.add(text);
frame.add(controlPanel);
frame.setVisible(true);
frame.pack();
//about where line 45 is
digits.setBorder(BorderFactory.createLineBorder(Color.black));
digits.setSize(new Dimension(30, 20));
text.add(digits);
JLabel greet = new JLabel("Welcome to Calculator!");
greet.setSize(30, 20);
greet.setVerticalAlignment(SwingConstants.TOP);
greet.setBorder(BorderFactory.createLineBorder(Color.black));
text.add(greet);
//about where line 60 is
JButton one = new JButton("1");
one.setSize(100, 30);
one.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
digits.setText("1");
}
});
controlPanel.add(one);
}
}
and this is the exception
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot use this in a static context
at Components.Interface.buttons(Interface.java:45)
at Components.Interface.main(Interface.java:60)
And the most shocking and confusing part is there is nothing written on both line numbers 45 and 60.
Seems to be some Ghost Exceptions. Any idea, why JVM is doing so ?