nullポインタ例外エラーが発生しましたが、何が問題なのかわかりません。
public static void main(String[] args) {
CDlist CD[] = new CDlist[5];
CD[0].add();
}
これが私のメインで、非常に単純です。5つのCDオブジェクトを作成し、最初のオブジェクトのaddメソッドを呼び出すだけです。
public boolean add(){
String author;
String title;
String songTitle;
int amount;
boolean result = false;
if(numUsed < length){
System.out.println("Please input the name of the CD you wish to add.");
title = input.next();
CD[numUsed].title = title;
System.out.println("Please input the author of the CD you wish to add.");
author = input.next();
CD[numUsed].title = title;
System.out.println("Please input the amount of songs you want to have.");
amount = input.nextInt();
for(int i = 0; i<amount; i++){
System.out.println("Add song name:");
songTitle = input.next();
CD[numUsed].song[amount] = songTitle;
}
numUsed++;
result = true;
}
return result;
}
これはCDlistクラスの私のaddメソッドです