簡體   English   中英

Java字數統計:錯誤:找不到符號。 Java編譯器

[英]Java word counts: Error: Cannot find symbol. Java compiler

請幫助我完成這項工作:(
(我的目標是計算input.txt文件中文件中的單詞。)

我在以下代碼中遇到8個編譯錯誤。 (所有找不到符號)編譯器指出:

  1. “ Paths.get”中的字母“ P”。
  2. “ Files.readAllLines”中的字母“ F”
  3. 符號“。” 在“ titleList.add(行)”中
  4. 符號“。” 在“ titleList.get”中
  5. 符號“。” 在“ st.add(filterList);”中
  6. 符號“。” 在“ filterList.removelAll(stopWordsArray);”中
  7. “ Map map = new Map <String,Integer>();”中的字母“ n”
  8. 符號“。” 在“ for(int i = 0; i <map.length && i <20; i ++)”中

有錯誤的代碼行以粗體顯示。

知道我的代碼有什么問題嗎? 我是Java的初學者,非常感謝您。

  public String[] process() throws Exception {
    String[] ret = new String[20];

    //TODO
    // Pass user id
    initialRandomGenerator(this.userName);

    //  Get the index into array
    Integer[] indexes = this.getIndexes();

    // Create Array to store input.txt
    String[] titleList = new String[10000];

    // Put each line of input.txt in Array

    // ERRORS HERE
    **for (String line : Files.readAllLines(Paths.get(this.inputFileName))){
        titleList.add(line);
    }**
    // Create array to store list of words to be proccess
    String[] filterList = new String[50000];

    // Look for words in file
     for (int i = 0; i < indexes.length; i++){
        // Tokennize, lower case, trim and stop delimiter.



         // ERRORS HERE 
         **StringTokenizer st = new StringTokenizer(titleList.get(indexes[i]).trim().toLowerCase(), this.delimiters);** 
        // Add word to Filter list array
         **st.add(filterList);**
     }

     // Remove stopWords from filter list array.
     // ERRORS HERE
     **filterList.removelAll(stopWordsArray);**      

     //  Declaring the map to count
    // ERRORS HERE 
    **Map<String, Integer> map = new Map< String, Integer>();**

    // Loop to count
    for (int i = 0; i < filterList.length; i++ ){   
        // Get the word
        String word = filterList[i];

        //Count the word
        if (map.get(word) != null) {
            // another occurence of an existing
            // word
            int count = map.get(word);
            count++;
            map.put(word, count);
        } else {
            // first occurence of this word
            map.put(word, 1);
        } 
    }
    // Sort the list by frequency in a descending order. Use sort function.
    // map.collections.sort( list, new Comparator<Map.Entry<word, count>>();


    // Display first 20 words.
    // ERRORS HERE        
    **for (int i =0; i < map.length && i < 20; i++){
        System.out.println(filterList[i]);**
    }

    return ret;
}

好,所以我明白了。 這有點困難,因為給定的文件無法使用IDE進行調試。 問題很簡單。

我在以下代碼中遇到8個編譯錯誤。 (所有找不到符號)編譯器指出:

1-“ Paths.get”中的字母“ P”。 (我需要導入庫:import java.nio.file.Paths;)

2-“ Files.readAllLines”中的字母“ F” (我需要導入庫:import java.nio.file.Files;)

3-符號“。” 在“ titleList.add(line)”中(方法.add僅在集合中可用,例如,我試圖在Array中使用ArrayList。)

4-符號“。” 在“ titleList.get”中

(.get方法僅在集合中可用,例如,我試圖在Array中使用它的ArrayList。)

5-符號“。” 在“ st.add(filterList);”中

(方法.add僅在集合中可用,例如ArrayList我試圖在StringTokenizer中使用它)

6-符號“。” 在“ filterList.removelAll(stopWordsArray);”中

(.get方法僅在集合中可用,例如,我試圖在Array中使用它的ArrayList。)

7-“地圖地圖=新地圖<字符串,整數>();”中的字母“ n”

(地圖需要初始化為地圖的一種類型。不僅是地圖。例如HashMap)

8-符號“。” 在“ for(int i = 0; i <map.length && i <20; i ++)”中

(長度不是地圖的屬性;必須使用大小。)

親切的問候

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM