英文:
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("**** UniLink System ****" + "\n" + "1. Login" + "\n" + "2. Quit");
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("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");
}
}
}
}
}
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.
"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 : ");
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>
专注分享java语言的经验与见解,让所有开发者获益!
评论