从不同的类调用方法引发了”在类com.company.UniLink中找不到主方法”的错误。

huangapple 未分类评论42阅读模式
英文:

calling method from different class raising "Main method not found in class com.company.UniLink" error

问题

我正在开发这个控制台应用程序它基本上是一个大学系统学生可以发布不同类型的帖子其他人可以回复他们的帖子

所以我有这个启动类

```java
public class startup {

    //不保留所有的学生

    public static void main(String args[])
    {
        boolean flag1 = true;
        **UniLink link = new UniLink();**

        while (flag1 == true)
        {
            System.out.println("**** UniLink System ****" + "\n" + "1. Login" + "\n" + "2. Quit");

            Scanner input_level_1 = new Scanner(System.in);
            int response_level_1 = input_level_1.nextInt();

            switch (response_level_1)
            {
                case 1:{
                    System.out.println("Enter Username : ");

                    Scanner input_level_1_1 = new Scanner(System.in);
                    String response_level_1_1 = input_level_1_1.nextLine();
                    **link.menu(response_level_1_1);**
                    break;
                }
                case 2:{
                    System.exit(0);
                }
                default:{
                    System.out.println("Please Try Again");
                }
            }

        }

    }
}

我正在使用一个名为Unilink的类,它正在执行所有繁重的工作并运行整个程序。我这样做是为了更好地封装和更清晰地呈现代码。我的菜单类允许执行以下任务。

                "1. New Event Post" + "\n" +
                "2. New Sale Post" + "\n" +
                "3. New Job Post" + "\n" +
                "4. Reply to Post" + "\n" +
                "5. Display my Post" + "\n" +
                "6. Display all Post" + "\n" +
                "7. Close Post" + "\n" +
                "8. Delete Post" + "\n" +
                "9. Log Out" + "\n" +
                "Enter Your Choice : ");

但我一直在收到这个错误

错误在类com.company.UniLink中找不到主方法请定义主方法为
   public static void main(String[] args)
或JavaFX应用程序类必须扩展javafx.application.Application

我感激任何帮助


<details>
<summary>英文:</summary>

I am working on this console base application.it is basically a university system on which a student can post different kind of posts and people can reply to there posts.


so, i have this startup class

public class startup {

//not keeping all the student

public static void main(String args[])
{
    boolean flag1 = true;
    **UniLink link = new UniLink();**

    while (flag1 == true)
    {
        System.out.println(&quot;**** UniLink System ****&quot; + &quot;\n&quot; + &quot;1. Login&quot; + &quot;\n&quot; + &quot;2. Quit&quot;);

        Scanner input_level_1 = new Scanner(System.in);
        int responce_level_1=input_level_1.nextInt();

        switch (responce_level_1)
        {
            case 1:{
                System.out.println(&quot;Enter Username : &quot;);

                Scanner input_level_1_1 = new Scanner(System.in);
                String response_level_1_1=input_level_1_1.nextLine();
                **link.menu(response_level_1_1);**
                break;
            }
            case 2:{
                System.exit(0);
            }
            default:{
                System.out.println(&quot;Please Try Again&quot;);
            }
        }

    }

}

}

I am using a class called Unilink which is doing all the heavy lifting and running the whole program. I did this for better encapluation and cleaner presentation of the code. My menu class allows to perform following tasks. 


            &quot;1. New Event Post&quot; + &quot;\n&quot; +
            &quot;2. New Sale Post&quot; + &quot;\n&quot; +
            &quot;3. New Job Post&quot; + &quot;\n&quot; +
            &quot;4. Reply to Post&quot; + &quot;\n&quot; +
            &quot;5. Display my Post&quot; + &quot;\n&quot; +
            &quot;6. Display all Post&quot; + &quot;\n&quot; +
            &quot;7. Close Post&quot; + &quot;\n&quot; +
            &quot;8. Delete Post&quot; + &quot;\n&quot; +
            &quot;9. Log Out&quot; + &quot;\n&quot; +
            &quot;Enter Your Choice : &quot;);
but i have been getting this error

Error: Main method not found in class com.company.UniLink, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application


I appericiate any help

</details>


huangapple
  • 本文由 发表于 2020年4月4日 06:20:34
  • 转载请务必保留本文链接:https://java.coder-hub.com/61021281.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定