所以我今天整天都在努力创建一个名为“Sport”的类的实例。我已经设置好我的代码,所以我运行用户界面,然后运行一个构造函数,然后运行另一个构造函数,该构造函数从文本文件加载运动值。
问题是,我显然创建对象的方式是错误的。真的可以使用一些帮助。
public static void seperateValues(String sportDetail)
{
String[] sportDetails = sportDetail.split(",");
System.out.println("Adding new sport to the Sport collection");
System.out.println(sportDetail);
/*
for(int i=0; i<sportDetails.length; i++) //just used for testing whether it was splitting correctly
{
System.out.println(sportDetails[i]);
} */
// name,usagefee,insurance,affiliationfees, then court numbers
//Tennis,44,10,93,10,11,12,13,14,15,16
int vlength;
vlength = sportDetail.length();
String[] sportDetailz;
sportDetailz = new String[vlength];
sportDetailz[0] = sportDetails[0]; //name
sportDetailz[1] = sportDetails[1]; //usage fees
sportDetailz[2] = sportDetails[2]; //insurance
sportDetailz[3] = sportDetails[3]; //afflcationfees
String vSportObjectName;
vSportObjectName = sportDetails[0];
String sportinstance;
sportinstance = sportDetails[0]; //this is the name of the sport which I'm hoping each loop around
//it will give a new name to
Sport sportinstance = new Sport(sportDetails);
//System.out.println(Sport.this.name);
}
错误信息:variable sportinstance is already defined in method seperateValues(java.lang.String)