0
我正在開發一個聽寫程序,其中我嘗試將學生輸入的文本與正確的文本進行比較,但編譯時出現錯誤,這對我沒有任何意義。Java長度方法錯誤
CODE:
String[] list_answer = exercise_english_1.answer.split("\\s+");
String[] list_responce = exercise_english_1.response.split("\\s+");
ArrayList<String> list_error = new ArrayList<String>();
for(int i = 0; i < list_answer.length(); ++i) {
if (list_responce[i].equals(list_answer[i]))
exercise_english_1_statistics.score += (double) 1/list_answer.length();
else
list_error.add(list_responce[i]);
}
錯誤:
C:\Users\?????\OneDrive\Java\Project\Prototype\Prototype.java:71: error: cannot find symbol
for(int i = 0; i < list_answer.length(); ++i) {
^
symbol: method length()
location: variable list_answer of type String[]
C:\Users\?????\OneDrive\Java\Project\Prototype\Prototype.java:73: error: cannot find symbol
exercise_english_1_statistics.score += (double) 1/list_answer.length();
symbol: method length()
location: variable list_answer of type String[]
C:\Users\?????\OneDrive\Java\Project\Prototype\Prototype.java:208: error: cannot find symbol
for(int i = 0; i < list_answer.length(); ++i) {
^
symbol: method length()
location: variable list_answer of type String[]
C:\Users\?????\OneDrive\Java\Project\Prototype\Prototype.java:210: error: cannot find symbol
exercise_french_1_statistics.score += (double) 1/list_answer.length();
^
symbol: method length()
location: variable list_answer of type String[]
4 errors
PS:對不起,我的英語不好,這不是我的母語...
數組具有'length'字段,而不是'length()'方法。 – Pshemo
也讀:[長度和長度()在java中](http://stackoverflow.com/questions/1965500/length-and-length-in-java) – Pshemo
但我有其他類似的數組在我的代碼和編譯並執行得很好。 –