英文:
Could not find main class in email app Java
问题
以下是您提供的代码的翻译部分:
错误:无法在项目模块中加载主类emailapp.Emailapp
java.lang.NoClassDefFoundError: emailapp/EmailApp(错误名称:emailapp/Emailapp)无法找到Java类,请帮忙,我正在尝试制作一个Java邮件应用程序。
因此有两个文件,一个用于主类,一个用于类,所以每次运行主文件时它都无法工作,并显示我遇到麻烦的错误。
我尝试在YouTube上寻找类路径的解决方案,但仍然出现此错误,即使对于环境变量也是如此。
import java.util.Scanner;
public class Email {
private String firstName;
private String lastName;
private String password;
private String department;
private int mailboxCapacity;
private String alternateEmail;
// 构造函数以接收名字和姓氏
public Email(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
System.out.println("已创建电子邮件:" + this.firstName + " " + this.lastName);
// 调用要求部门的方法并返回
this.department = setDepartment();
}
// 询问部门
private String setDepartment() {
System.out.print("请输入部门\n1 代表销售\n2 代表开发\n3 代表会计\n0 代表无");
Scanner in = new Scanner(System.in);
int depChoice = in.nextInt();
if (depChoice == 1) {return "销售";}
else if (depChoice == 2) {return "开发";}
else if (depChoice == 3) {return "会计";}
else {return "";}
}
// 生成随机密码
// 设置邮箱容量
// 设置备用电子邮件
// 更改密码
}
SECOND FILE
package emailapp;
public class EmailApp {
public static void main(String[] args) {
// TODO Auto-generated method stub
Email eml = new Email("John", "Carl");
}
}
***请帮助***
英文:
Error: Unable to load main class emailapp.Emailapp in module projects
java.lang.NoClassDefFoundError: emailapp/EmailApp (wrong name: emailapp/Emailapp) Cant Find Java class please help im trying to make an email application in Java
So there are two files one for the main and one for the class so everytime i run the main file it doesnt work and shows that error that i am having troubles
I try solutions for classpaths around youtube but still got this error even for environment variables
import java.util.Scanner;
public class Email {
private String firstName;
private String lastName;
private String password;
private String department;
private int mailboxCapacity;
private String alternateEmail;
// Constructor to recieve first name and last name
public Email(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
System.out.println("EMAIL CREATED:" + this.firstName + " " +this.lastName);
// Call a method that is asking for the department and return
this.department = setDepartment();
}
// Ask the Department
private String setDepartment() {
System.out.print("Enter the department\n1 for Sales\n2 for Development\n3 for Accounting\n0 for none");
Scanner in = new Scanner(System.in);
int depChoice = in.nextInt();
if (depChoice == 1) {return "sales";}
else if (depChoice == 2) {return "dev";}
else if (depChoice == 3) {return "acct";}
else {return "";}
}
// Generate a random password
// Set the mailbox capacity
// Set the alternate email
// Change the password
}
SECOND FILE
package emailapp;
public class EmailApp {
public static void main(String[] args) {
// TODO Auto-generated method stub
Email eml = new Email("John","Carl");
}
}
Please help
答案1
得分: 0
以下是翻译好的内容:
你是如何运行主程序的?使用命令行还是集成开发环境(IDE)?
假设你在IDE中运行这个程序,你应该首先尝试清除并重新构建你的项目。
而且这段代码看起来非常奇怪,最好重构为:
public static void main(String[] args) {
System.out.print("输入部门\n1 代表销售\n2 代表开发\n3 代表会计\n0 代表无");
Scanner in = new Scanner(System.in);
int depChoice = in.nextInt();
String department = "";
if (depChoice == 1) department = "销售";
else if (depChoice == 2) department = "开发";
else if (depChoice == 3) department = "会计";
Email eml = new Email("John", "Carl", department);
}
英文:
How do you run your Main? Cmd Line or IDE?
Suppose you're running this in IDE, you should try clean
rebuild
your project first.
And the code looks very odd, better refactor to
public static void main(String[] args) {
System.out.print("Enter the department\n1 for Sales\n2 for Development\n3 for Accounting\n0 for none");
Scanner in = new Scanner(System.in);
int depChoice = in.nextInt();
String department = "";
if (depChoice == 1) department = "sales";
else if (depChoice == 2) department = return "dev";
else if (depChoice == 3) department = return "acct";
Email eml = new Email("John","Carl", department);
}
答案2
得分: 0
你已将类名给定为EmailApp
,但它正在尝试加载Emailapp
。如果你正在使用命令行界面(CLI),请检查大小写敏感性。如果你使用的是Eclipse或其他集成开发环境(IDE),在导入正确的包后,它应该可以正常工作。
由于你的两个文件位于不同的包中,所以Email
类无法在EmailApp
类中被识别。首先导入你正在使用的所有正确包。
英文:
You have given your class name as EmailApp
but it is trying to load Emailapp
if your using CLI then check for case sensitivity. If you are using Eclipse OR any other IDE then is should work fine after importing correct packages.
Since your both files are in different packages so Email class
can not be identified in EmailApp class
First import all correct packages you are using.
专注分享java语言的经验与见解,让所有开发者获益!
评论