저는 오늘 하루 종일 '스포츠'라는 클래스의 인스턴스를 만들려고 애 쓰고 있습니다. 사용자 인터페이스를 실행하여 생성자를 실행 한 다음 텍스트 파일에서 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)
오류 메시지를 이미지가 아닌 질문의 텍스트로 제공하십시오. – Kninnug
변수 이름을 다시 사용하고 있습니다. 하지마. –