我在大学任务中偶然发现了一些编译错误。 经过一段时间的尝试修复它,我真的找不到解决方案来纠正它们。
以下是实现非确定性有限自动机的程序的构造函数。 在这种情况下,我正在使用Hashsets和Hashmaps。
public NFA(Set<String> states, Set<String[]> transitions, String start, Set<String> end) { this.start = start; this.end = end; this.active = this.start; Map<String, String> x = new HashMap<String, String>(); //create placeholder map //Insert states into map for (String s: states) { this.states.put(s, x); //Placeholder map used for this line } //Assign transitions to corresponding states. for (String[] t: transitions) { //this line throws the error. if (!states.containsKey(t[0]) || !states.containsKey(t[2])) { throw new IllegalArgumentException("Transition Data Corrupted!"); } else { this.states.get(t[0]).put(t[1], t[2]); } } }函数调用在我的readIn方法中,该方法从文件中提取NFA的构造数据。
result = new NFA(states, transitions, start, end);编译器错误javac宣布如下:
NFA.java:27: error: cannot find symbol if (!states.containsKey(t[0]) || !states.containsKey(t[2])) { ^ symbol: method containsKey(String) location: variable states of type Set<String> NFA.java:27: error: cannot find symbol if (!states.containsKey(t[0]) || !states.containsKey(t[2])) { ^ symbol: method containsKey(String) location: variable states of type Set<String>
此外,我从eclipse-ide中得到一个错误:
The method containsKey(String) is undefined for the type Set<String>I stumbled across some compiler-errors for my university assignment. After some time of trying to fix it, I don't really find a solution to correct them.
The following is the constructor for a program that implements a Nondeterministic Finite Automata. I am working with Hashsets and Hashmaps in this case.
public NFA(Set<String> states, Set<String[]> transitions, String start, Set<String> end) { this.start = start; this.end = end; this.active = this.start; Map<String, String> x = new HashMap<String, String>(); //create placeholder map //Insert states into map for (String s: states) { this.states.put(s, x); //Placeholder map used for this line } //Assign transitions to corresponding states. for (String[] t: transitions) { //this line throws the error. if (!states.containsKey(t[0]) || !states.containsKey(t[2])) { throw new IllegalArgumentException("Transition Data Corrupted!"); } else { this.states.get(t[0]).put(t[1], t[2]); } } }the function call is in my readIn method which pulls the construction data for the NFA from a file.
result = new NFA(states, transitions, start, end);The compiler-errors javac announces are the following:
NFA.java:27: error: cannot find symbol if (!states.containsKey(t[0]) || !states.containsKey(t[2])) { ^ symbol: method containsKey(String) location: variable states of type Set<String> NFA.java:27: error: cannot find symbol if (!states.containsKey(t[0]) || !states.containsKey(t[2])) { ^ symbol: method containsKey(String) location: variable states of type Set<String>
Furthermore, I get an error from the eclipse-ide:
The method containsKey(String) is undefined for the type Set<String>最满意答案
您需要对集合使用contains(String value) 。 在Set<T> ,没有键值关系 。
You need to use contains(String value) for sets. In a Set<T>, there is no key-value relation.
更多推荐
发布评论