문제

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.

도움이 되었습니까?

해결책

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();
    }    
}

다른 팁

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

    public static void main(String[] args){
        new HotelGuiForm();
    }    
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top