未经检查或不安全的操作

时间:2012-11-22 00:34:20

标签: java

无法确定导致java编译器抛出的内容

uses unchecked or unsafe operations.

正在进行的课程如下:

import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Vector;



public class Proj2 {

/**
 * args[0] the maximum depth of the trie
 * args[1] is the number of substrings to print
 * args[2] name of first file containing text
 * args[3] name of second file containing text
 * @param args
 */
public static void main(String[] args) throws Exception {
    String input = args[0];
    int one = 0;
    int two = 0;
    String a;
    String b;
    String[] tokens = input.split("\\s+");
    if (tokens.length != 4) {
        throw new IllegalArgumentException(
                "Argument must contain two integers and two filenames.");
    }
    try {
        one = Integer.parseInt(tokens[0]);
        two = Integer.parseInt(tokens[1]);
    } catch (Exception e) {
        System.out.println("First two arguments must be integers");
    }
    System.out.println("" + one + " " + two + " " + tokens[2] + " "
            + tokens[3]);
    try {

        Scanner sc1 = new Scanner(new File(tokens[2]));
        ;

        Scanner sc2 = new Scanner(new File(tokens[3]));
        String s = "";
        while (sc1.hasNext())
            s += sc1.nextLine();

        Character[] in1 = new Character[s.length()];
        for (int i = 0; i < s.length(); i++) {
            in1[i] = s.charAt(i);
        }
        s = "";
        while (sc2.hasNext())
            s += sc2.nextLine();
        Character[] in2 = new Character[s.length()];
        for (int i = 0; i < s.length(); i++) {
            in2[i] = s.charAt(i);
        }
        Trie<Character> tree1 = new Trie<Character>(in1,
                Integer.parseInt(tokens[0]));
        Trie<Character> tree2 = new Trie<Character>(in2,
                Integer.parseInt(tokens[0]));
        Vector<Vector<Character>> max = tree1.getMax(Integer
                .parseInt(tokens[1]));
        Vector<Integer> max_n = tree1.getMaxCount(Integer
                .parseInt(tokens[1]));

        System.out.println("Sequence    # in " + tokens[2] + "\t# in "
                + tokens[3]
                + "\n--------    --------------\t--------------");

        for (int i = 0; i < max.size(); i++) {
            int n = 0;
            if (tree2.consist(max.get(i)))
                n = tree2.getCount(max.get(i));
            s = "";
            for (int j = 0; j < max.get(i).size(); j++)
                s += max.get(i).get(j);
            System.out.println(s + "\t    " + max_n.get(i) + "\t\t\t" + n);
        }
    } catch (Exception e) {
        System.out.println("Incorrect file name");
    }

}

}

我必须修改类以捕获更多异常,并且在我使用args [1],args [2]等代替解析标记之前它没有丢弃它。但由于我指定那些是整数,我很困惑为什么编译器仍然抛出错误。任何见解都会非常感激。谢谢。导致错误的代码是实例化树。

0 个答案:

没有答案