(Beginner) Need some help with display
Hello I am new to the forum so first I would like to say hello!
I am a beginner and just started learning to use Java 2 days ago. I am having an issue with getting a display box to show up. I am working from a tutorial at the moment and I am using the Eclipse IDE however when I try to compile and run I receive an error that states
Severity and DescriptionPath Resource Location Creation Time Id
The serializable class Board does not declare a static final serialVersionUID field of type long Uadventure/src/uadventure Board.java line 5 1352751766061 40
Here is the code I am working with:
package uadventure;
import javax.swing.JFrame;
public class Board extends JFrame {
public Board() {
add(new Board());
setTitle("Display");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(1280, 800);
setLocationRelativeTo(null);
setVisible(true);
setResizable(false);
}
public static void main(String[] args) {
new Board();
}
}
Getting a box to display just isn't working. Like I said I am working from a tutorial and I even tried using the tutorial code as well and the same problem arises. I have been doing alot of reading and understand how things work but I seem to struggle getting the basics of a project going once I can get the display working I can then move onto getting things together. Any help with this problem would be greatly appreciated.
Thanks
Justin
Re: (Beginner) Need some help with display
Are you getting a compile time error, or a compile time warning? The message you posted is a warning, and the code should have compiled and class file generated based upon the code you posted (the warning has to do with Serialization - see Serializable Objects (The Java™ Tutorials > Java Naming and Directory Interface > Java Objects in the Directory) )
1 Attachment(s)
Re: (Beginner) Need some help with display
It is showing as a warning. After I compile and run it the console gives me these errors.
Exception in thread "main" java.lang.StackOverflowError
at java.util.HashMap.getEntry(Unknown Source)
at java.util.HashMap.get(Unknown Source)
at sun.awt.AppContext.get(Unknown Source)
at com.sun.java.swing.SwingUtilities3.getDelegateRepa intManager(Unknown Source)
at javax.swing.RepaintManager.getDelegate(Unknown Source)
at javax.swing.RepaintManager.addDirtyRegion(Unknown Source)
at javax.swing.JComponent.repaint(Unknown Source)
at java.awt.Component.repaint(Unknown Source)
at javax.swing.JComponent.setBackground(Unknown Source)
at javax.swing.LookAndFeel.installColors(Unknown Source)
at javax.swing.LookAndFeel.installColorsAndFont(Unkno wn Source)
at javax.swing.plaf.basic.BasicPanelUI.installDefault s(Unknown Source)
at javax.swing.plaf.basic.BasicPanelUI.installUI(Unkn own Source)
at javax.swing.JComponent.setUI(Unknown Source)
at javax.swing.JPanel.setUI(Unknown Source)
at javax.swing.JPanel.updateUI(Unknown Source)
at javax.swing.JPanel.<init>(Unknown Source)
at javax.swing.JPanel.<init>(Unknown Source)
at javax.swing.JPanel.<init>(Unknown Source)
at javax.swing.JRootPane.createGlassPane(Unknown Source)
at javax.swing.JRootPane.<init>(Unknown Source)
at javax.swing.JFrame.createRootPane(Unknown Source)
at javax.swing.JFrame.frameInit(Unknown Source)
at javax.swing.JFrame.<init>(Unknown Source)
at uadventure.Board.<init>(Board.java:7)
at uadventure.Board.<init>(Board.java:8)
at uadventure.Board.<init>(Board.java:8)
at uadventure.Board.<init>(Board.java:8)
And uadventure.board repeats many times
Here is an image of eclipse
Attachment 1528
Re: (Beginner) Need some help with display
Think about how the program proceeds. The main method is entered, and you create a Board. Doing so calls the Board class constructor. When the constructor is called, it attempts to add a Board, which in turn calls the Constructor, and so on ad infinitum. In other words, the code repetitively calls itself. Don't try to add a class to itself in this manner.
Re: (Beginner) Need some help with display
Ah I see thank you very much I got it working and I can see how it was repeating itself.