獲取錯誤:需要數組,但找到字符串。 我檢查並重新檢查,但無法找到我的代碼有任何問題。出了什麼問題? 我已經在一年前被介紹給java了,但是直到我開始開發一個開發圖書館管理系統的項目時,才意識到我的知識存在嚴重的缺陷。編譯器錯誤:需要數組,但找到字符串
import java.util.Scanner;
public class library{
book[] bk = new book[5];
public static void main(String[] args){
Scanner input = new Scanner(System.in);
library mainObj = new library();
mainObj.addBooks();
}
public void addBooks(){
Scanner input = new Scanner(System.in);
System.out.print("Book Name: ");
String bk = input.nextLine();
System.out.print("Author Name: ");
String aun = input.nextLine();
System.out.print("Id: ");
String i = input.nextLine();
bk[book.getTotalBookCount()] = new book(bk, aun, i);
}
}
class book{
String name;
String authorName;
String id;
static int totalBookCount = 0;
book(String bkn, String aun, String i){
name = bkn;
authorName = aun;
id = i;
totalBookCount++;
System.out.println("Book Added!! ");
}
}
請提供[mcve](注意「最小」),至少指向錯誤的位置。 –
library.java:39:error:array required,but String found \t \t bk [book.getTotalBookCount()] = new book(bk,aun,i); \t \t^ 1錯誤 – ooodddbbb
@AlexeiLevenkov okrighty。 – ooodddbbb