gpt4 book ai didi

java - 在电子邮件应用程序 Java 中找不到主类

转载 作者:行者123 更新时间:2023-12-01 16:56:16 26 4
gpt4 key购买 nike

Error: Unable to load main class emailapp.Emailapp in module projects

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;


// 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
}

第二个文件

package emailapp;

public class EmailApp {

public static void main(String[] args) {
// TODO Auto-generated method stub
Email eml = new Email("John","Carl");
}

}

请帮忙

最佳答案

你如何运行你的Main?命令行还是 IDE?假设您在 IDE 中运行它,您应该首先尝试clean rebuild您的项目。而且代码看起来很奇怪,最好重构为

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

关于java - 在电子邮件应用程序 Java 中找不到主类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61586264/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com