Question

I have looked up a few different solutions, but I keep either getting a "Illegal Start of Expression" error or a "class, interface or enum expected" error.

So I just want to make my JFrame class my main class, because currently my project has no main class.

This is what the start of the code looks like:

public class HotelGuiForm extends javax.swing.JFrame {
public   HotelGuiForm() {
    initComponents();


}

and when I insert the Main class code, it just gets errors all over. Anyone able to help me out?

EDIT:

public class HotelGuiForm extends javax.swing.JFrame {
public static void main(String[] args);
{
  public   HotelGuiForm() {
    initComponents();


}
//Rest of Code
}

This gives me a illegal start of expression on the public HotelGuiForm(), and if I put the public static void main above the public class I get a missing class enum or interface.

Was it helpful?

Solution

You have incorrect code format.

  1. You can not have a semi colon after you main function, before its body.
  2. You can not write class constructor inside main function. You can call it from main.
  3. Constructor should be inside the class body not inside main.

Try this.

public class HotelGuiForm extends javax.swing.JFrame {
    public   HotelGuiForm() {
        initComponents();
    }

    public static void main(String[] args){
        HotelGuiForm HGF = new HotelGuiForm();
    }    
}

OTHER TIPS

public class HotelGuiForm extends javax.swing.JFrame {
    public   HotelGuiForm() {
        initComponents();
    }

    public static void main(String[] args){
        new HotelGuiForm();
    }    
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top