Hello其他务实的程序员,我有我开发的这个程序,这是一个用java编写的社交网络程序,该程序的主要功能是允许用户:添加朋友,删除朋友,看看谁拥有最多朋友们,看看谁具有最高的影响力和退出计划的能力。
与任何程序一样会有一两个亮点,对我而言,这是一个java运行时异常的情况,在我尝试通过查看它是否能在没有主程序包的情况下工作或者我试图改变我编写程序的方式无济于事。
这是继续支持的错误消息:
Select:
[1] Add Friend
[2] Delete Friend
[3] List Friends
[4] Friends of Friends
[5] Most Popular
[6] Most Influencer
[7] Exit
7
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: uelbook.Person
at uelbook.UELbook.main(UELbook.java:20)
我的主要课程的第20行是UELbook,下面是:
Person listfriends=new Person();
UELbook:
package uelbook;
import java.util.*;
import java.io.*;
public class UELbook {
public static void main(String[] args) {
UELbook uelbook = new UELbook();
//test your code here
Scanner scanner=new Scanner(System.in);
System.out.println("Select:");
System.out.println("[1] Add Friend");
System.out.println("[2] Delete Friend");
System.out.println("[3] List Friends");
System.out.println("[4] Friends of Friends");
System.out.println("[5] Most Popular");
System.out.println("[6] Most Influencer");
System.out.println("[7] Exit");
int choice=scanner.nextInt();
Person listfriends=new Person();
while(choice!=7){
int num=0;
//ADD
if(choice==1){
System.out.println("ID: ");
String id=scanner.nextLine();
System.out.println("Username: ");
String username=scanner.nextLine();
System.out.println("Password: ");
String password=scanner.nextLine();
listfriends.set(id, username, password);
listfriends.addFriend();
}
//DELETE
if(choice==2){
System.out.println("ID: ");
String id=scanner.nextLine();
System.out.println("Username: ");
String username=scanner.nextLine();
System.out.println("Password: ");
String password=scanner.nextLine();
listfriends.set(id, username, password);
listfriends.removeFriend();
}
//LIST
if(choice==3){
for(int i=0;i<1;i++){
System.out.println(listfriends.list);
}
}
System.out.println("ID: ");
String id=scanner.nextLine();
System.out.println("Username: ");
String username=scanner.nextLine();
System.out.println("Password: ");
String password=scanner.nextLine();
//REMOVE
if(choice==7){
System.exit(0);
}
if(choice==8){
System.out.println("ERROR! Please choose from the options.");
}
}//WHILE LOOP EXIT
}
public void addPerson(String id, String firstname, String lastname) throws PersonExistsException {
//list.add(ID);
// list.add(firstname);
//list.add(lastname);
}
public String getPerson(String id) throws NoSuchCodeException {
return id;
}
public void addFriendship(String id1, String id2) throws NoSuchCodeException {
id1=id1;
id2=id2;
}
public Collection<String> listFriends(String id) throws NoSuchCodeException {
return null;
}
public Collection<String> friendsOfFriends(String id) throws NoSuchCodeException {
return null;
}
//The methods returns true if the file has been loaded,
//false in case of any errors
public boolean loadFile(String file) {
return false; // remove this in the implementation
}
//The methods returns true if the file has been saved,
//false in case of any errors
public boolean saveFile(String file) {
return false; // remove this in the implementation
}
public String mostPopular() {
return null; // remove this in the implementation
}
public String mostInfluencer() {
return null; // remove this in the implementation
}
}
人:
package UELbook;
import java.util.*;
import java.io.*;
public class Person {
String ID;
String firstname;
String lastname;
ArrayList<String>list=new ArrayList<String>();
public static void main(String[]args){
}
//CONSTRUCTOR
public void set(String ID, String firstname, String lastname){
setID(ID);
setFirstName(firstname);
setLastName(lastname);
}
//SETTERS
public void setID(String ID){
ID=ID;
}
public void setFirstName(String FirstName){
firstname=FirstName;
}
public void setLastName(String LastName){
lastname=LastName;
}
//GETTERS
public String getID(){
return ID;
}
public String getFirstName(){
return firstname;
}
public String getLastName(){
return lastname;
}
public void addPerson(String id, String firstname, String lastname) throws uelbook.PersonExistsException {
list.add(ID);
list.add(firstname);
list.add(lastname);
}
}
人存在异常:
package uelbook;
@SuppressWarnings("serial")
public class PersonExistsException extends Exception {
}
没有此类代码例外:
package uelbook;
@SuppressWarnings("serial")
public class NoSuchCodeException extends Exception {
}
非常感谢任何有用的提示。
答案 0 :(得分:0)
您的人类正在使用 UELbook 包。
据推测应该是 uelbook 。
(更新以提供解释....)
只是一个约定(尽管遵循99.99%的时间)包名称应该全部小写。 Oracle states the following原因如下:
包名称全部用小写写成,以避免与 类或接口的名称。
在OP的代码中有:
所以你在课程 UELbook 和包 UELbook 之间发生了冲突。将软件包名称 UELbook 更改为 uelbook 应该从技术角度解决您的问题。但是,作为相关问题,之后您应更改包 uelbook 或您的班级 UELbook 的名称,以消除所有歧义。