Java"找不到符号"使用javac进行编译时出错

时间:2016-05-30 02:12:50

标签: java javac selection-sort

编译java文件时遇到问题。顺便说一句,我是java的新手。

以下是代码:

**MatriceSelectionSort.java**

package wsmt_lab1;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MatriceSelectionSort {

    public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Missing FileName! Folositi: java MatriceSelectionSort C:\\wsmt\\matrice.txt");
            System.exit(1);
        }
        String fileName = args[0];
        try {
            List<List<Integer>> matrix = readMatrix(fileName);
            for (List<Integer> row : matrix) {
                SelectionSort.sort(row);
            }
            writeResult(fileName, matrix);
        } catch (Exception e) {
            System.out.println("Nu pot citi/parsa fisierul");
            e.printStackTrace();
        }       
    }

    private static List<List<Integer>> readMatrix(String fileName) throws IOException {
        List<List<Integer>> matrix = new ArrayList<List<Integer>>();
        try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
            String line = br.readLine();
            while (line != null) {
                List<Integer> row = new ArrayList<Integer>();
                String[] tokens = line.split("\\s+");
                for (String token : tokens) {
                    if (token != null && !token.isEmpty()) {
                        row.add(Integer.parseInt(token));
                    }
                }
                matrix.add(row);
                line = br.readLine();
            }
        }
        return matrix;
    }

    private static void writeResult(String fileName, List<List<Integer>> matrix) throws IOException {
        try (BufferedWriter bw = new BufferedWriter(new FileWriter(fileName, true))) {
            bw.newLine(); bw.newLine();
            for (List<Integer> row : matrix) {
                for (Integer item : row) {
                    bw.write(item + " ");
                }
                bw.newLine();
            }
        }
    }

}

并且,第二个文件:

SelectionSort.java

package wsmt_lab1;

import java.util.List;

public class SelectionSort {

    public static List<Integer> sort(List<Integer> list)
    {
        for (int i = 0; i < list.size(); i++)
        {
            int min = i;
            int j;
            for (j = i + 1; j < list.size(); j++)
            {
                if (list.get(j) < list.get(min))
                {
                    min = j;
                }
            }
            int tmp = list.get(min);
            list.set(min, list.get(i));
            list.set(i, tmp);
        }
        return list;
    }
}

编译后,我收到此错误:

C:\boian\wsmt_lab1\src\wsmt_lab1>javac MatriceSelectionSort.java
MatriceSelectionSort.java:22: error: cannot find symbol
                                SelectionSort.sort(row);
                                ^
  symbol:   variable SelectionSort
  location: class MatriceSelectionSort
1 error
你能帮帮我吗?我使用Eclipse,看起来一切都很完美......

谢谢!

0 个答案:

没有答案